14 posts
Location
U, S & A
Posted 04 January 2016 - 03:55 PM
So, I wrote this code not too long ago but never tested it. Now I tested it and its outputting an error code: ERROR BIOS14: (don't remember the exact text but said 'then' expected at line 28)
Now here's the problem - there's already a 'then' at line 28… here's the code:
Spoiler
--: nuclear control for Chernoshima
-- Variables & Such
nuke = peripheral.wrap('nuclear_reactor_0')
mon = peripheral.wrap('monitor_0')
--[[]]--
local function populate()
x, y = mon.getSize() -- 7, 12
mon.setCursorPos(1, 1)
while true do
if nuke.isActive() then
mon.blit(' ON ', '5555555', '0000000')
else
mon.blit(' OFF ', 'eeeeeee', '0000000')
end
sleep()
end
end
--[[]]--
local function switch()
if eve[4] == 1 then
if nuke,isActive() == true then --(this is the problem line BTW)
rs.setOutput('false', 'top')
elseif nuke.isActive() == false then
rs.setOutput('true', 'top')
end
end
end
--[[]]--
function overHeat()
while true do
if nuke.getHeat() / nuke.getMaxHeat() >= 0.75 then
rs.setOutput('flase', 'top')
end
sleep(5)
end
end
--**--Start--**--
populate()
while true do
eve = {os.pullEvent('monitor_touch')}
parallel.waitForAny(overHeat, populate, switch)
end
If its something stupid, please forgive me, if not, thank you for helping me
3057 posts
Location
United States of America
Posted 04 January 2016 - 04:13 PM
You have a comma (,) instead of a period (.)
--#current
nuke,isActive()
--#corrected
nuke.isActive()
8543 posts
Posted 04 January 2016 - 06:29 PM
Moved to Ask a Pro.
14 posts
Location
U, S & A
Posted 06 January 2016 - 03:47 PM
You have a comma (,) instead of a period (.)
--#current
nuke,isActive()
--#corrected
nuke.isActive()
Goddammit! I knew it was something stupid, thanks man, I'll try it ASAP
14 posts
Location
U, S & A
Posted 13 January 2016 - 12:58 AM
Sorry for the late reply, I tested, it worked!… to a point: it runs but does not perform like I envisioned it. I've boiled it down to event handling, which I don't really know who to do… if anyone can point me to a good tutorial or just plain help me here on how to correctively and efficiently manage events, I'll greatly appreciate it! Or maybe I just don't know how to use the parallel API correctly…
Edited on 13 January 2016 - 12:03 AM
95 posts
Location
A CPU some where in Bolton, UK
Posted 13 January 2016 - 01:14 AM
Sorry for the late reply, I tested, it worked!… to a point: it runs but does not perform like I envisioned it. I've boiled it down to event handling, which I don't really know who to do… if anyone can point me to a good tutorial or just plain help me here on how to correctively and efficiently manage events, I'll greatly appreciate it! Or maybe I just don't know how to use the parallel API correctly…
Here is a link to the event page on the CC wiki
http://computercraft.info/wiki/Os.pullEvent
7083 posts
Location
Tasmania (AU)
Posted 13 January 2016 - 02:10 AM
You're misusing
rs.setOutput() (you're passing in your boolean as a string, and in the wrong order at that).
And yeah, your coroutine management is broken. Without going into too much detail as to how and why, BB's first law of coroutines is "you probably don't need to be using coroutines" - trying to do so usually means you're already going down the wrong track. I'd refactor along these lines:
--: nuclear control for Chernoshima
-- Variables & Such
local nuke = peripheral.wrap('nuclear_reactor_0')
local mon = peripheral.wrap('monitor_0')
local x, y = mon.getSize()
--[[]]--
local myTimer = os.startTimer(0)
while true do
local myEvent = {os.pullEvent()}
if myEvent[1] == "timer" and myEvent[2] == myTimer then
if nuke.getHeat() / nuke.getMaxHeat() >= 0.75 then
rs.setOutput("top", false)
end
mon.setCursorPos(1, 1)
if nuke.isActive() then
mon.blit(' ON ', '5555555', '0000000')
else
mon.blit(' OFF ', 'eeeeeee', '0000000')
end
myTimer = os.startTimer(1)
elseif myEvent[1] == "monitor_touch" and myEvent[4] == 1 then
rs.setOutput("top", not nuke.isActive())
end
end
Edited on 13 January 2016 - 01:12 AM
14 posts
Location
U, S & A
Posted 20 January 2016 - 06:58 PM
Thanks for all sugestions, while looking for something else for another of my protects I found that eve = {os.pullEvent()} and the fact that you can use it as a table blew my mind! I've been getting a little better at it. I'll try BombBlocke's suggestion. Thanks again!