Moved to the appropriate forum.
I'm trying to make an increment button that will have a clk and increment an inputted variable by another user defined variable.
If anyone can help me with my crappy gate code (I've never used LUA before and i know this is VERY incorrect) or can help me make a gate system to do this, I'd appreciate that very much.
Code:GateActions["increment"] = { group = "Arithmetic", name = "Increment", inputs = { "A", "B", "Clk"}, output = function(gate, A) local clk = ( Clk > 0 ) if ( clk ) then A = B + A return A end end, label = function(Out, A) return "A += " .. B .. " = " .. Out end }
Sorry if this is in the wrong thread, I'm new to the site
PS: this is not E2
Moved to the appropriate forum.
The problem is that A is an input. Changing A in this execution doesn't mean it will be different in the next execution, since its value is retrieved from the input each time. You could do it with two clock inputs - one for reading from input A into gate memory and one for adding input B to the value stored in the gate memory.
I can wire anything directly into anything! I'm the Professor!
-Professor Hubert Farnsworth
There is, but its a +1, and what I am shooting for is a gate that will read a value and add/increment it by a static amount when it is pinged(or really allowed) by a clk.
I'm very bad with LUA, as I'm used to a modified C# (i believe it was). Perchance you could script/show me what you are explaining?
Sorry about that, thanks for the move.Drunkie: Moved to the appropriate forum.
What I mean is something like this, I guess:
It's just the current increment gate with a Resetvalue input added, and it resets gate.Memory to Resetvalue instead of 0 when you trigger Reset. The important thing here, though, is that you use a value that is saved in the gate (i.e. gate.Memory). You were using the variable A, which being an input is not saved in the gate but retrieved from inputs every execution.Code:GateActions["increment"] = { group = "Arithmetic", name = "Increment", inputs = { "A", "Clk", "Reset", "Resetvalue" }, output = function(gate, A, Clk, Reset, Resetvalue) local clk = ( Clk > 0 ) local reset = ( Reset > 0 ) if ( gate.PrevValue ~= clk ) then gate.PrevValue = clk if ( clk ) then if ( gate.Memory == nil ) then gate.Memory = A else gate.Memory = gate.Memory + A end end end if( gate.PrevReset ~= reset ) then gate.PrevReset = reset if ( reset ) then gate.Memory = Resetvalue end end return gate.Memory end, label = function(Out, A) return "LastNum += " .. A .. " = " .. Out end }
I'm not sure if I see this making any real change though. Both the Increment gate and the up/down counter have an input for how long they step, and if you want to add a constant or something you can always add the incrementer to the other thing with an add gate.
I can wire anything directly into anything! I'm the Professor!
-Professor Hubert Farnsworth
Bookmarks