Discuss Scratch

Siena7997
Scratcher
14 posts

Problems with "wait" blocks

Hi! So I have a project that if you(the player) touches the sprite for ten seconds, it will send you to a certain location.

but heres the problem, even if you touch the sprite for one second and just move on, after 10 seconds it will still send you to that location.

PLS HELP!!

(my code so far)

this is the sprite

when green flag clicked
forever

if <touching [ player] ?> then


wait (10) secs
broadcast [ too_long!]
else

end

player code

when I receive [ too long!]
go to x: ((x)) y: ((y))

when green flag clicked
forever
set [ x] to (mouse x)
set [ y] to (mouse y)
end


Please help!

Last edited by Siena7997 (April 10, 2023 14:46:23)

medians
Scratcher
1000+ posts

Problems with "wait" blocks

Also, it would be better to go to the mouse-pointer like this instead of using 2 variables:

Last edited by medians (April 10, 2023 15:01:33)

ideapad-320
Scratcher
1000+ posts

Problems with "wait" blocks

Your issue is it teleports after 10 seconds, not if you touch it for 10 seconds.
You need to make a variable to keep track of the last time the player started touching the teleporter. I will call that variable “last”. It can be called anything. Please note this will not work if you reset the timer.
In a forever loop, check if the player is touching the teleporter. if it is not touching it, set last to the timer. If it is touching, check if timer is at least 10 more than last. If yes, teleport.
forever
if <touching [something v] ? > then
if <((last)+(10)) < (timer)> then
broadcast [teleport v]
end
else
set [last v] to (timer)
end
end
Siena7997
Scratcher
14 posts

Problems with "wait" blocks

ideapad-320 wrote:

Your issue is it teleports after 10 seconds, not if you touch it for 10 seconds.
You need to make a variable to keep track of the last time the player started touching the teleporter. I will call that variable “last”. It can be called anything. Please note this will not work if you reset the timer.
In a forever loop, check if the player is touching the teleporter. if it is not touching it, set last to the timer. If it is touching, check if timer is at least 10 more than last. If yes, teleport.
forever
if <touching [something v] ? > then
if <((last)+(10)) < (timer)> then
broadcast [teleport v]
end
else
set [last v] to (timer)
end
end
but how do you make it stop when you touch it?

Last edited by Siena7997 (April 27, 2023 13:33:38)

Powered by DjangoBB