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

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Superbloxen
Goomba
Goomba
Posts: 4
Joined: Tue Jun 28, 2022 6:46 pm

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

Postby Superbloxen » 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?

WildW
Rocky Wrench
Rocky Wrench
Posts: 676
Joined: Thu Dec 14, 2017 2:21 pm
Flair: C# more like Db
Pronouns: he/him

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

Postby WildW » Sun Oct 13, 2024 8:49 pm

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.

Superbloxen
Goomba
Goomba
Posts: 4
Joined: Tue Jun 28, 2022 6:46 pm

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

Postby Superbloxen » Sun Oct 13, 2024 9:17 pm

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.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 8 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari