Stormworks: Build and Rescue

Stormworks: Build and Rescue

Not enough ratings
Toggleable boutons and style [On/Off]
   
Award
Favorite
Favorited
Unfavorite
Microcontrollers: Cockpit, Microcontroller
Tags: v0.7.4
File Size
Posted
Updated
32.389 KB
18 May, 2019 @ 6:28am
18 May, 2019 @ 7:06am
2 Change Notes ( view )

Subscribe to download
Toggleable boutons and style [On/Off]

Description
Presentation

This microcontroller allow you to create a 2x2 (by default) maximum 6 toggleables buttons screen.
You can use a bigger screen, but don't forget to set correct values for the " w " in the sub-table " pos " of each buttons.

Settings

- Change the background color :
globalBackGroundColor = function() screen.setColor(89, 89, 89) end

{"btn_1", display=true, pos={x=1, y=2, w=62, h=9}, borderAndTextColor=function() screen.setColor(0, 0, 0) end, backgroundColor=function() screen.setColor(255, 255, 255) end, text="Button 1", outputChannel=1, defaultState=false}

Field
Description
First field
the first field ( "btn_1" in this exemple) is the name of the button, not used anywhere. just a memo for you. If you don't use it, you can remove the field and don't forget the comma.
display
This field show or hide the button. For not used buttons for exemple.
pos
This field is the position from the top-left corner of the screen. In order : x, y, width, height
borderAndTextColor
This field define the color of borders and text. When the button is toggled, the borders and text take the background color.
backgroundColor
This field define the color of the button background. When the button is toggled, the background take the borders and text color.
text
This field define the displayed text of the button.
channel
Define the exit channel of the signal with the exit composite signal. If you change it, don't forget to update module after the LUA module.
defaultState
Define the default state when the microcontroller is initialized.
7 Comments
lokefs3000 1 Jan, 2020 @ 11:20pm 
function onTick()
-- Read the touchscreen data from the script's composite input
inputX = input.getNumber(3)
inputY = input.getNumber(4)
isPressed = input.getBool(1)
isPressed = input.getBool(2)

-- Check if the player is pressing the rectangle at (10, 10) with width and height of 20px
isPressingRectangle = isPressed and isPointInRectangle(inputX, inputY, 10, 10, 20, 20)
isPressingRectangle = isPressed and isPointInRectangle(inputX, inputY, 20, 10, 20, 20)

-- Set the composite output, on/off channel 1
output.setBool(1, isPressingRectangle)
end

height rectH
function isPointInRectangle(x, y, rectX, rectY, rectW, rectH)
return x > rectX and y > rectY and x < rectX+rectW and y < rectY+rectH
end

function onDraw()

if isPressingRectangle then
screen.drawRectF(10, 10, 20, 20)
else
screen.drawRect(10, 10, 20, 20)

if isPressingRectangle then
screen.drawRectF(10, 10, 20, 20)
else
screen.drawRect(20, 10, 20, 20)


end
end
lokefs3000 1 Jan, 2020 @ 11:19pm 
heres the script if you want to help
lokefs3000 1 Jan, 2020 @ 11:18pm 
can anyone help me with this lua script i cant figure out whats wrong
ToothpasteMain 22 Aug, 2019 @ 3:11pm 
Very nice and super easy to use. Could you make a microcontroller where only one button can be enabled at a time; where if one button is pressed, any other enabled buttons would be toggled off?
pr0c3lla 20 May, 2019 @ 9:40am 
nice! does this work with the 1x1 monitor?
Viscy 19 May, 2019 @ 3:04am 
Thank you very much <3

Thumbs Up!
Great Work
lolo 18 May, 2019 @ 8:25am 
So nice, your eplanation of the script is a big plus ! Thx