Stormworks: Build and Rescue

Stormworks: Build and Rescue

Not enough ratings
Dynamic Up/Down counter
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
161.882 KB
15 Oct, 2022 @ 12:12pm
5 Dec, 2022 @ 10:18am
6 Change Notes ( view )

Subscribe to download
Dynamic Up/Down counter

Description
Up/Down counter with an increment that can be multiplied.
LUA is not my primary programming language, so there might be stuff that can be improved. If so, please let me know!

Features:
-Variable increment (A feature the standard Up/Down counter does not have).
-Precise clamp.
-Option to turn the clamp off.
-Lots of comments in code to make it easier to understand.

Code:
-- Up/Down counter with changable Increment --LICENSE: Feel free to use it on any of your creations but leave this line unchanged. Made by MaxMustermann. x = 0 INCREMENT_X = 0.01 --The value that is later multiplied by "incrementMultipier" and then outputed CLAMP = true -- Clamps (restricts) the min/max output of the counter. ("MAX_VALUE", "MIN_VALUE") MAX_VALUE = 1 -- Highest possible value **CANT BE LESS THAN "MIN_VALUE" else the script will break! MIN_VALUE = -1 -- Lowest possible value **CANT BE GREATER THAN "MAX_VALUE" else the script will break! RESET_VALUE = 0 function calcActualChange() incrementMultipier = input.getNumber(1) -- Multiplier for "incrementX" **HAS TO BE MORE THAN 0 FOR "x" TO INCREASE** return (INCREMENT_X*incrementMultipier) end function onTick() increaseX = input.getBool(1) -- **Bool** from axis threshold (Put the seat axis at 100%) decreaseX = input.getBool(2) -- **Bool** from axis threshold (Put the seat axis at 100%) reset_counter = input.getBool(3) if reset_counter == true then -- Sets "x" to the value of "RESET_VALUE" if variable reset_counter is == true x = RESET_VALUE end if increaseX == true then if CLAMP == true then x = math.min((x+calcActualChange()), MAX_VALUE) -- Sets x to the lowest value. --If "x=x+calcActualChange()" would be **more** than "MAX_VALUE", "MAX_VALUE" is the lowest an therefore picked. else x = x+calcActualChange() -- Increases x if "CLAMP"=false. end end if decreaseX == true then if CLAMP == true then x = math.max((x-calcActualChange()), MIN_VALUE) -- Sets x to the highest value --If "x=x-calcActualChange()" would be **less** than MIN_VALUE", "MIN_VALUE" is the highest an therefore picked else x = x-calcActualChange() -- Decreases x if "CLAMP"=false. end end output.setNumber(1, x) -- Outputs x at composite channel 1. end
11 Comments
Star Killer 18 Jan @ 11:04am 
I'm also having the problem of not finding it in game, I tried to resubscribe and wait for steam to register, but still nothing.
YarikBurnHorizon 27 Jul, 2024 @ 6:55pm 
I can give you an advanced fire control system.
YarikBurnHorizon 27 Jul, 2024 @ 6:53pm 
thank you. you best !
MaxMustermann  [author] 5 Dec, 2022 @ 11:12am 
Hi, try going into your steam libary right-click on Stormworks -> select "properties" -> go to the workshop tab -> select the Up/Down counter and click "unsubscribe" then go back to this page and download it again.
I hope this helps as it worked for me.
TMC Christian 5 Dec, 2022 @ 10:57am 
That's the same concept for sure. I restarted steam and it downloaded an update, but in game there doesn't seem to be any change to it
MaxMustermann  [author] 5 Dec, 2022 @ 10:26am 
I actually made the first version of this for one of my ladder trucks to make the boom move slower when fully extended :D So quite similar application
TMC Christian 5 Dec, 2022 @ 10:23am 
That was quick, thank you for that! I've been racking my head for months trying to figure out how to dynamically change the increment so I could slow the rotation of a turret as the camera zooms in for longer range shots, and this does that perfectly.
MaxMustermann  [author] 5 Dec, 2022 @ 10:19am 
You might have to close and reopen steam for the update to show up
MaxMustermann  [author] 5 Dec, 2022 @ 10:06am 
Hi! I have not implemented a reset functionality yet... But I'm adding it rn :steamthumbsup:
TMC Christian 5 Dec, 2022 @ 9:52am 
Is there a way to add a reset function like the standard up/down counter?