This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
godsrock's profile picture

Increasing values based on how many times a function runs

Started by godsrock, 28 March 2014 - 03:36 AM
godsrock #1
Posted 28 March 2014 - 04:36 AM
So, i'm trying to create a 2 buttons on a monitor. One is for increasing redstone signal strength the other for decreasing. The problem i'm having is compounding the variable x in a function. Basicly all I'm doing is making the x=2 or 3. The only thing i know how to do is possible stack* the buttons like a page turn. Is there another way to do this like logging how many times a function was pulled and using it as a variable?


os.loadAPI("touchpoint")
t = touchpoint.new("right")
local x = 2
t:add("+",
function()
redstone.setAnalogOutput("left",x+1)
end
,40 , 15, 45, 18, math.pow(2,x), colors.lime)
t:draw()
t:run()
CometWolf #2
Posted 28 March 2014 - 05:34 AM
This is pretty straight forward, just store the plus one in the variable

x = x+1
redstone.setAnalogOutput("left",x)
Edited on 28 March 2014 - 04:34 AM
Bomb Bloke #3
Posted 28 March 2014 - 07:35 AM
Another option is to just use rs.getAnalogOutput, which is effectively tracking this value for you already.
godsrock #4
Posted 28 March 2014 - 06:21 PM
Thanks, I don't know why i was just stuck on that for a long time.