Loop once per second? (beginner help)

Is there a simple way to have a loop run once per second rather than 20 times a second?

I'd like the player to automatically move up once a second. In game I've got:

on load do
	player_up = event.py
end

on loop do
	tell event.player to
		call "move_up"
	end
end

and in player I've got:

on enter do
	goto 12,13
end

on move_up do
	wait 1 then
		player_up--
		goto event.px,player_up
	end
end

My player waits one second, and then moves up 20 times a second, rather than waiting a second between each move.

As a complete beginner, this is probably a terrible way to accomplish this but I'm trying to just pick up the basics. I'm sure there's something very simple I'm missing. Is there an easy answer, or can you point me somewhere I can dig in and learn more?

1 Like

You could use a basic variable that counts up and only executes on the 20th loop, then resets.

So something like:

on loop do
    loopClock++
    if loopClock==20 then
        (code)
        loopClock = 0
    end
end

There's probably a cleaner way but that's simple.

5 Likes

Thank you! That does what I needed. (Open to hearing if anyone has other/more ideas but otherwise I'm ready to stumble forward to my next problem.)