Stormworks: Build and Rescue

Stormworks: Build and Rescue

H2O Delirious Feb 27, 2020 @ 11:59am
How to make a timer in LUA?
I read about it on different forms but didn’t understand anything, maybe something is different in the game?
< >
Showing 1-15 of 15 comments
Ra-Ra-Rasputin Feb 27, 2020 @ 12:05pm 
Does it have to be specifically in LUA?

You can do this by the following workaround:

ADD A: 1/60 B: Memory out
ADD output: Memory input

Since the microcontroller runs in 60 ticks / second (or close enough, it seems accurate with my real life stopwatch) this should work as a timer.

Does the fluffypony site mentioned in the guide have any clock or timer feature within it?
tribalart Jun 2, 2020 @ 8:18am 
its old but i was searching today and finally found a simple solution :


A = 0

function onTick()
if FirstCondition == 1 then
A = A + 1


if A > 350 then
-- do something after the first Condition and 350 tick (?)
A = 0
end
end
end



Last edited by tribalart; Jun 2, 2020 @ 8:19am
shadouv Jul 14, 2023 @ 9:50am 
if i put a=a+1 i get error ... im trying all time but cant get it to work
ShizNator Jul 14, 2023 @ 12:03pm 
This would run a timer and execute it's code every 5 seconds if a toggle input is on
a=0 ticks=300 function onTick() btn=input.getBool(1) if btn then a=a+1 if a>=ticks then --You Would Put Your code for whatever you wanna do here. a=0 end end end

if a=a+1 causes an error it's because you're not declaring it and calling a nil value or you made a typo and calling a nil value.

Lua is case sensative so a and A are not the same.

Post your code here and you can post it inbetween [code] [/code] tags to keep it's spaces etc..
Haven <3 Aug 18, 2023 @ 10:27am 
Late, but what if I wanna do something every second? I'm trying to make a countdown timer, so I would need something to delay it every second (the amount it counts down is a property slider from 1-9), here is my code;
while count >= 0 and start == true do -- Whichever way you can delay by one second screen.drawText(w/2,h/2,count) count = count - 1 end
Sharp777 Aug 18, 2023 @ 1:14pm 
why not use the micro controller timer blocks
ShizNator Aug 18, 2023 @ 2:32pm 
Originally posted by Sharp777:
why not use the micro controller timer blocks
How to make a timer in LUA?
Sharp777 Aug 19, 2023 @ 1:35am 
Timer block --- numerical counter value into lua script
Sharp777 Aug 19, 2023 @ 1:46am 
Use valves from clock . You need a measure of time cant use tick as basis for timer not consistant
ShizNator Aug 19, 2023 @ 8:15am 
Yeah and my timer code can be changed for whatever time your want.

Just change ticks=300 which is 5 seconds in ticks to what you want. (desired timer seconds * 60)

So to run it's code every 1 second you would put ticks=60. Because 60 ticks = 1 second
Last edited by ShizNator; Aug 19, 2023 @ 8:17am
Haven <3 Aug 19, 2023 @ 10:19am 
Originally posted by ShizNator:
Yeah and my timer code can be changed for whatever time your want.

Just change ticks=300 which is 5 seconds in ticks to what you want. (desired timer seconds * 60)

So to run it's code every 1 second you would put ticks=60. Because 60 ticks = 1 second

The only issue is that'll require it to run in onTick, but I need it to run in onDraw or else screen.drawText wouldn't work (but I could be wrong).
ShizNator Aug 19, 2023 @ 10:32am 
Originally posted by JustHaven!:
Originally posted by ShizNator:
Yeah and my timer code can be changed for whatever time your want.

Just change ticks=300 which is 5 seconds in ticks to what you want. (desired timer seconds * 60)

So to run it's code every 1 second you would put ticks=60. Because 60 ticks = 1 second

The only issue is that'll require it to run in onTick, but I need it to run in onDraw or else screen.drawText wouldn't work (but I could be wrong).
Well simply...
a=0 ticks=60 function onTick() btn=input.getBool(1) end function onDraw() if btn then a=a+1 if a>=ticks then --You Would Put Your code for whatever you wanna do here. a=0 end end end
Ra-Ra-Rasputin Aug 25, 2023 @ 2:05pm 
Originally posted by ShizNator:
Yeah and my timer code can be changed for whatever time your want.

Just change ticks=300 which is 5 seconds in ticks to what you want. (desired timer seconds * 60)

So to run it's code every 1 second you would put ticks=60. Because 60 ticks = 1 second
*62 ticks.
Why? Because fúck you that's why. :lunar2019deadpanpig:
No, i have no idea why it's that figure either.
ShizNator Aug 25, 2023 @ 2:13pm 
Because just like their DLC their heads where up in Space.
Ra-Ra-Rasputin Aug 25, 2023 @ 3:37pm 
Actually, there is an arguable reason on mathematics on why 62 is better, as opposed to 60, but if they wished to bank on that, 64 is a number that's a successive power of 2, meaning it's a geometric sequence. If you go for 62 instead of 60, there's no real reason to not go for 64.
< >
Showing 1-15 of 15 comments
Per page: 1530 50

Date Posted: Feb 27, 2020 @ 11:59am
Posts: 15