Posted 23 January 2016 - 02:47 PM
I am trying to setup a solar generator control system for Extra Utilities Solar Generators. I am using Openperipherals to connect them and the apis from the mod. Everything works fine in my program except one thing…the variables…
For some reason, the program creates the variable of the energy amount in the generator when the program starts, and works properly. But the variable does not change until the program restarts…how do I get it to refresh the variable while the program is running to update the energy amount and continue the program.
Please let me know if this is possible at all or not. I'm pretty sure I've seen it before in other people's programs, but not sure how they did it. I would say I know a fair bit of LUA, as I have created fairly complicated programs in my past. If it's not possible, I guess that's fine, but I want some way to automatically control the generators. Thanks in advance!
The pastebin…
http://pastebin.com/qPLshg40
The code…
For some reason, the program creates the variable of the energy amount in the generator when the program starts, and works properly. But the variable does not change until the program restarts…how do I get it to refresh the variable while the program is running to update the energy amount and continue the program.
Please let me know if this is possible at all or not. I'm pretty sure I've seen it before in other people's programs, but not sure how they did it. I would say I know a fair bit of LUA, as I have created fairly complicated programs in my past. If it's not possible, I guess that's fine, but I want some way to automatically control the generators. Thanks in advance!
The pastebin…
http://pastebin.com/qPLshg40
The code…
generator1 = peripheral.wrap("extrautils_generatorsolar_6")
generator2 = peripheral.wrap("extrautils_generatorsolar_7")
generator3 = peripheral.wrap("extrautils_generatorsolar_8")
local energy1 = generator1.getEnergyStored()
local energy2 = generator2.getEnergyStored()
local energy3 = generator3.getEnergyStored()
function display()
print("")
term.clearLine(1,3)
term.setCursorPos(1,3)
print("Solar 1: " .. energy1 .. " / 100000 RF")
print("")
term.clearLine(1,5)
term.setCursorPos(1,5)
print("Solar 2: " .. energy2 .. " / 100000 RF")
print("")
term.clearLine(1,7)
term.setCursorPos(1,7)
print("Solar 3: " .. energy3 .. " / 100000 RF")
end
function scan()
term.clear()
term.setCursorPos(1,1)
print("Scanning solar.")
sleep(.5)
term.clear()
term.setCursorPos(1,1)
print("Scanning solar..")
sleep(.5)
term.clear()
term.setCursorPos(1,1)
print("Scenning solar...")
sleep(.5)
term.clear()
term.setCursorPos(1,1)
print("Solar scanned...")
end
function main()
scan()
monitorGenerator1()
while true do
display()
os.sleep(1)
end
end
function generatorMonitor()
while true do
monitorGenerator1()
sleep(1)
end
end
function monitorGenerator1()
if energy1 == 100000 then
term.clearLine(1,9)
term.setCursorPos(1,9)
print("Solar 1 is full...")
redstone.setOutput("top", true)
end
if energy1 == 0 then
term.clearLine(1,9)
term.setCursorPos(1,9)
print("Solar 1 is filling...")
redstone.setOutput("top", false)
end
end
main()