Now, for the reason im here. I've been writing this small set code for the last 2 days (my first attempt at a whole "OS" for my "Big Reactors" Reactor), hitting small road bumps here and there, nothing too crazy though. Until now, that is. I'm trying to write this "if, else" statement, but cant get it to work!
Here's the idea:
I want to set up a piece of code at the end of the script that EITHER activates subscript "a", or subscript "b" (depending on: If "a" ran last, run "b". If "b" ran last, run "a"). Script "a" saves the currently stored "RF", compares it to last ticks stored "RF" (saved by script "b" ), and lastly, setting control rods accordingly based on the comparison. Next time around, script "b" does exactly the same, but checks script "a" for its temporary "RF/t" place holder instead.
Basically, I'm trying to implement an "RF/t usage" variable, then use it to set my reactor's control rods for optimal energy generation. I just can't get the "if, else" statement to work properly. Here's the code:
local counter = counter
local adj = adj
local num1 = num1
local num2 = num2
local tmp1 = tmp1
local tmp2 = tmp2
local I = I
local O = O
counter = counter + 1
if counter == 1 then
num1 = nrg
tmp1 = nrg - num2
tmp2 = tmp1/nrg
I = math.floor(tmp2*100)
adj = I - O
else
num2 = nrg
tmp1 = nrg - num1
tmp2 = tmp1/nrg
O = math.floor(tmp2*100)
adj = O - I
counter = 0
end
After this^ I tell it to get all the control rod insertion %s, divide by # of control rods, then add the "adj" variable to the control rod insertion %. After all is done, it sets the control rods to the new %. But the above code is all I really need help with.
I hope this all makes sense!
As a final note, I'm trying really hard to learn lua, so don't just spit out the correct code or something. I want explanations! I want to know why it works, and the logical steps it takes!
Thanks in advance!
P.S. I don't write on forums much, so I don't know hot to put a spoiler for the code. Sorry about that.