I am trying to test continuously for a particular condition: camera Z angle. If the angle is over a certain value, I’d like to start an object moving (“Move” block) and if the angle is a different value, stop the object from moving. The problem is that once the object starts moving, the code stops evaluating and updating other parts of the code. I’ve tried serial and parallel but nothing seems to work. Any help is appreciated.
very cool script!
The reason why your code stops evaluating is because it jumps into the
StartTimer - function. The code inside the forever block will then wait until the movement of the Tester item is complete.
In your case the duration of the motion is 10 seconds, so the script will wait that time until the
move block inside the
StartTimer function completes, and then returns evaluation.
Below are some solutions! Please feel free to check out this space and click the remix button to take a look at the different solution examples.
Solution a: run separately block
To prevent the forever loop from waiting for the StartTimer function to complete, you can place all blocks you want to ‘skip’ waiting for as separate execution into the run separately block.
To prevent the move block to be called every frame while looking over the threshold, we use a variable to check if the tester item is done moving or not.
Solution b: do not use blocks that complete over time
This solution involves adding a higher Z value to the item position every frame. The downside is that you can not easily define the duration over which this movement should take place. It is frame/performance dependent, too.
Hope this helped
Thanks for your prompt reply. That is very helpful. I will go with solution A as I care about timing.
Next, related question. Since you don’t support local variables or dynamically created variables, how would I create multiple timers that don’t “step” on each other? I thought about spawning multiple animating objects but they all still would refer to the same counter/state variables and those would overwrite each other.
for this case you can use functions with parameters to set-up different timers.
I’ve updated the example space, feel free to use the remix button to copy it. The space has a new multiple timers - scene which makes use of functions and parameters to control the behavior of unique timer items.
Here’s the breakdown of how it’s done:
- The setTimer function accepts parameters for…
- The item we want to use as timer,
- Look thresholds
- Movement time
- The moveTimer function moves the timer item up
- The resetTimer function places the timer back on the ground again
To prevent the moveTimer function to be called whenever the conditions to move the item are true, I’m using a rather unorthodox way to check the item’s state; by using colors.
If the item is red, it means that it is moving and another movement call can’t be made. If it is white, it can be moved again. This is not an optimal way to treat item states, so I’ll be in touch with our devs to look into blocks that could help with that (e.g. setting and getting properties on items).
Hope this demo helps giving you some more insight on using functions with CoBlocks!
Thanks so much. I will try it out. It’d be nice if there were dedicated timer functions so we didn’t have to use objects as “local variables.” But I’ll try this for now.