This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-15 20:24:39

SD7
Scratcher
Registered: 2011-09-15
Posts: 100+

Sensing no change in x-coordinate?

Is there a function that will sense if a moving object (say, a ball) is no longer changing its x-coordinate after about 3 seconds or so? I made a pong game, and sometimes it gets stuck going straight up an down, and it would be nice to reset it if that happens. Thanks


http://img834.imageshack.us/img834/4411/signaturespacegame2.png

Offline

 

#2 2011-09-15 20:55:32

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: Sensing no change in x-coordinate?

SD7 wrote:

Is there a function that will sense if a moving object (say, a ball) is no longer changing its x-coordinate after about 3 seconds or so? I made a pong game, and sometimes it gets stuck going straight up an down, and it would be nice to reset it if that happens. Thanks

set [moving  v] to true.
repeat until <moving = false> {
set [xpos  v] to (x position).
wait 0.5 seconds.
if <(x position) = (xpos)> {
set  [moving  v] to false.
}
}

The above script checks every 0.5 seconds to see if it is moving at all.  Then, add this:

set [xpos  v] to (xposition).
wait 3 seconds.
if <(x position) = (xpos)> {
code if it hasn't moved here.
}

Put that all in the "repeat until" and everything after it, in the first and second script, into a forever loop.  I think that will work.

Last edited by Greenatic (2011-09-15 20:56:06)

Offline

 

Board footer