Page 1 of 1

[Question] About Wait Times/Cooldowns in luna.lua Scripts

Posted: Sun Oct 13, 2024 8:22 pm
by Superbloxen
I recently tried to make a script while messing around in the editor, but realized that certain code would instantly repeat itself and cause the character to move at extremely high speeds for simple scripts that just add +1 to the character's height or speed. Is there any way to create a wait() command or other sort of cooldown to balance out scripts that do things like this?

Re: [Question] About Wait Times/Cooldowns in luna.lua Scripts

Posted: Sun Oct 13, 2024 8:49 pm
by WildW
Superbloxen wrote:
Sun Oct 13, 2024 8:22 pm
I recently tried to make a script while messing around in the editor, but realized that certain code would instantly repeat itself and cause the character to move at extremely high speeds for simple scripts that just add +1 to the character's height or speed. Is there any way to create a wait() command or other sort of cooldown to balance out scripts that do things like this?
You're not being very clear on what exactly you mean by "certain code", maybe try posting an example here and me or someone else can show you the intended way of solving that problem.

To broadly answer your question though, you can utilize the global function onTick, which is ran once for every game tick (~1/65th of a second) or use Routine.wait/Routine.waitFrames.

Re: [Question] About Wait Times/Cooldowns in luna.lua Scripts

Posted: Sun Oct 13, 2024 9:17 pm
by Superbloxen
Here's a snippet of the code in question:

Code: Select all

local MaxSpeedMinus = - 10
function onTick()
     if player.keys.up == KEYS_DOWN then
        if player.speedY > MaxSpeedMinus then
                   player.speedY = (player.speedY - 1) 
                   end
         end
end

I just wanted to add a short cooldown between speed increases so the character wouldn't just jump to max speed instantly when I held the key down.