Stormworks: Build and Rescue

Stormworks: Build and Rescue

Help please with touch screen
I make a touch screen through LUA, but I can’t understand how to make a toggle switch, not a push button.
< >
Showing 1-3 of 3 comments
Ra-Ra-Rasputin Feb 29, 2020 @ 4:26pm 
Make the push button switch a boolean variable, for this i assume you don't have the button set up so that it fires on every redraw update, but rather only once per press.
Let's say you have a boolean called myToggleSwitch and a button
(i'll simplify the code for brevity)
if ButtonPressed myToggleSwitch = !myToggleSwitch

While i'm not as inherently familiar with LUA, it should support basic functionality like this.
On the off-chance that it doesn't, the other solution is a state machine like this:

if ButtonPressed and ButtonToggle = false ButtonToggle = true else if ButtonPressed and ButtonToggle = true ButtonToggle = false

Using the latter it's easy to also make a button have nested looping states, like such:

if ButtonPressed if ButtonState = 1 ButtonState = 2 else if ButtonState = 2 ButtonState = 3 else if ButtonState = 3 ButtonState = 4 else if ButtonState = 4 ButtonState = 1

But it's also possible with a simple X += 1 if > 4 X = 1

PS Writing LUA without semicolon terminators makes me feel dirty.
Last edited by Ra-Ra-Rasputin; Feb 29, 2020 @ 4:41pm
yungmono Feb 29, 2020 @ 8:02pm 
Originally posted by Ra-Ra-Rasputin:
Make the push button switch a boolean variable, for this i assume you don't have the button set up so that it fires on every redraw update, but rather only once per press.
Let's say you have a boolean called myToggleSwitch and a button
(i'll simplify the code for brevity)
if ButtonPressed myToggleSwitch = !myToggleSwitch

While i'm not as inherently familiar with LUA, it should support basic functionality like this.
On the off-chance that it doesn't, the other solution is a state machine like this:

if ButtonPressed and ButtonToggle = false ButtonToggle = true else if ButtonPressed and ButtonToggle = true ButtonToggle = false

Using the latter it's easy to also make a button have nested looping states, like such:

if ButtonPressed if ButtonState = 1 ButtonState = 2 else if ButtonState = 2 ButtonState = 3 else if ButtonState = 3 ButtonState = 4 else if ButtonState = 4 ButtonState = 1

But it's also possible with a simple X += 1 if > 4 X = 1

PS Writing LUA without semicolon terminators makes me feel dirty.
If you are not familiar with lua I have a way more easy one, for me i don't do that. First I get the push signal on lua then I will output it as composite. Second i will connect the signal to a push to toggle block. Thirdly I will convert it back to composite and put the value back and give a new name for the variable. This definitely works as all my lua scripting toggle button is using this, this is very easy
Ra-Ra-Rasputin Mar 1, 2020 @ 1:22am 
Sure, you can always wire-spaghetti it with the electronics pieces, but that's not really what was asked for.
The person has asked LUA help for before as well, so i'm intentionally omitting that solution as a choice myself.
Last edited by Ra-Ra-Rasputin; Mar 1, 2020 @ 1:23am
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Feb 29, 2020 @ 3:21pm
Posts: 3