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

Can someone test this code for me?

Started by WestWindsDemon, 04 January 2016 - 02:55 PM
WestWindsDemon #1
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
KingofGamesYami #2
Posted 04 January 2016 - 04:13 PM
You have a comma (,) instead of a period (.)


--#current
nuke,isActive()
--#corrected
nuke.isActive()
Lyqyd #3
Posted 04 January 2016 - 06:29 PM
Moved to Ask a Pro.
WestWindsDemon #4
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
WestWindsDemon #5
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
Mr_Programmer #6
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
Bomb Bloke #7
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
WestWindsDemon #8
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!