Update redstoneAnalogOutput.lua

Add comments
This commit is contained in:
toastonrye
2022-08-08 19:44:24 -05:00
committed by GitHub
parent c775958254
commit fac7e221b3

View File

@@ -6,11 +6,11 @@ end
-- toastonrye's example: Redstone Analog Output -- toastonrye's example: Redstone Analog Output
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
local w, h = term.getSize() local w, h = term.getSize() -- dimensions to use when drawing the sub frame
local main = basalt.createFrame() local main = basalt.createFrame()
:show() :show()
:setBackground(colours.blue) :setBackground(colours.blue) -- using colours to easily determine what frame I'm in
local sub = main:addFrame() local sub = main:addFrame()
:setPosition(2,2) :setPosition(2,2)
@@ -20,28 +20,28 @@ local sub = main:addFrame()
local rFrame = sub:addFrame("redstoneFrame") local rFrame = sub:addFrame("redstoneFrame")
:setPosition(1,1) :setPosition(1,1)
:setSize(25,5) :setSize(25,5)
:setMoveable(true) :setMoveable(true) -- the next release of Basalt will fix spelling to :setMovable
:setBackground(colours.red) :setBackground(colours.red)
-- Redstone Analog Output -- Redstone Analog Output
local redstoneAnalog = rFrame:addLabel() local redstoneAnalog = rFrame:addLabel() -- label that displays the value of the slider & Redstone output
:setPosition(18,3):setText("1") :setPosition(18,3):setText("1")
redstone.setAnalogOutput("left", 1) redstone.setAnalogOutput("left", 1) -- initialize the redstone output to 1, to match the above label
rFrame:addLabel() rFrame:addLabel() -- draw a label on the frame
:setText("Redstone Analog Output") :setText("Redstone Analog Output")
:setPosition(1,2) :setPosition(1,2)
rFrame:addSlider() rFrame:addSlider()
:setPosition(1,3) :setPosition(1,3)
:onChange(function(self) :onChange(function(self) -- when a player interacts with the slider, update the variable redstoneAnalog
redstoneAnalog:setText(self:getValue()) redstoneAnalog:setText(self:getValue())
end) end)
:setMaxValue(15) :setMaxValue(15) -- max value of the slider, default 8. Redstone has 15 levels (16 including 0)
:setSize(15,1) :setSize(15,1) -- draw the slider to this size, without this redstoneAnalog value can have decimals
redstoneAnalog:onChange(function(self) redstoneAnalog:onChange(function(self) -- when the slider value changes, change the Redstone output to match
redstone.setAnalogOutput("left", tonumber(self:getValue())) redstone.setAnalogOutput("left", tonumber(self:getValue()))
basalt.debug(self:getValue()) basalt.debug(self:getValue())
end) end)