Hi everyone,
this may be a total noob question. I've got a chunk of pretty basic script that doesn't work the way I expected it to. I've found a way to make it work, so I don't need suggestions for that, but I'd like to understand why the first thing I tried didn't work. Just for curiosity's sake, really.
Basically what I have is two sprites, one of which moves around randomly, the other one I control. The controlled one chases the other one, when it "catches" (touches) it, the random one disappears.
So the code that didn't work for the randomly moving sprite was:
when gf clicked show repeat until <touching [other sprite]> glide <pick random [3] to [8]> secs to x: <pick random [-240] to [240]> y: <pick random [-180] to [180]> wait [0.1] secs end hideWith this, when the sprites touch, sometimes the random one does hide. Sometimes it hides after a few seconds of "being touched", and sometimes it doesn't hide at all.
Offline
How the repeat until block works is, at the end of the loop, it does this check: if the argument is false, it repeats the loop. If it is true, it breaks out of the loop. So, is checks at the END of the loop code whether it is touching or not.
Last edited by SciTecCf (2012-07-02 14:24:09)
Offline
problem is it only checks every 0.1 seconds, and during gliding it doesn't check either. how about instead "point towards sprite" (set rotation off firstly so it appears straight) then "move X steps" and it should follow AND check (get rid of wait 0.1 seconds)
Offline
Can you upload the project for me to see?
Offline
SciTecCf wrote:
It's the "wait 0.1 secs" block. How the repeat until block works is, at the end of the loop, it does this check: if the argument is false, it repeats the loop. If it is true, it breaks out of the loop. So, is checks at the END of the loop code whether it is touching or not.
i thought it checks at the start, which is why on my scripts it doesn;t repeat if it is not necessary to. btw, don;t forget to read my explanation above!
Offline
Borrego6165 wrote:
problem is it only checks every 0.1 seconds, and during gliding it doesn't check either. how about instead "point towards sprite" (set rotation off firstly so it appears straight) then "move X steps" and it should follow AND check (get rid of wait 0.1 seconds)
Actually, it checks every 1.1 secs.
Offline
SciTecCf wrote:
Borrego6165 wrote:
problem is it only checks every 0.1 seconds, and during gliding it doesn't check either. how about instead "point towards sprite" (set rotation off firstly so it appears straight) then "move X steps" and it should follow AND check (get rid of wait 0.1 seconds)
Actually, it checks every 1.1 secs.
well that makes it worse! which is why you need to get rid of "glide to" and replace with the other scripts.
Last edited by Borrego6165 (2012-07-02 14:27:37)
Offline
Oooooohhhhh.....!
Yes, that makes perfect sense - it does stuff inside the loop for anything from roughly 3 - 9 seconds before it ever even loops back around to check if the touching statement is true, that's why it would sometimes hide quite soon, and sometimes take a while.
Gee, that was really quite obvious actually
Thanks so much, guys!
Offline
The problem with your script is that the sprite glides. It could touch the other one halfway through without hiding because it is still moving. Basically, repeat-until scripts cannot stop while running the thing inside of them. What they do is check if something is true. If it is they do nothing and stop looping. Otherwise, they run what is inside of them, loop, and check again.
Offline
Put the hide in another script:
when gf clicked forever if <touching sprite 2> hide endChange the other script to this:
When gf clicked glide <pick random (3) to (8)> secs to x: <pick random (-240) to (240)> y: <pick random (-180) to (180)>Hope this helps.
Last edited by JH1010 (2012-07-05 01:33:15)
Offline