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

attempt to call boolean error

Started by coolmodi, 20 May 2012 - 02:43 AM
coolmodi #1
Posted 20 May 2012 - 04:43 AM
Hi,

i'm not good at programming (i sucked at java in school :P/>/>) but thought why not make a little program with this mod to controll my IC² CASUC.
So far i have:

ronoff=0
sucstatus=0
rstatus=0
storef1=0
storef2=0
storef3=0
storef4=0
euflow=0
temp=0

function ron()
ison=colors.test(redstone.getBundledInput("back"), 64)
return ison
end

function euon()
eu=colors.test(redstone.getBundledInput("back"), 4)
return eu
end

function getstates()
if ronoff==0 and ron()==false then
  rstatus=0
  elseif ronoff==0 and ron()==true then
  rstatus=1
  else
  rstatus=2
end
if eu()==true then
  euflow=1
  else
  euflow=0
end
end

function drawdisp()
term.clear()
term.setCursorPos(11,1)
print("Welcome to reactor controll!")
term.setCursorPos(11,2)
print("Available actions:")
term.setCursorPos(13,3)
if rstatus==0 or rstatus==1 then
  print("1 - Start reactor")
  else
  print("1 - Shut down reactor")
end
term.setCursorPos(13,4)
print("2 - Shut down system NYI")
end

function start()
rs.setBundledOutput("back",2)
sleep(3)
rs.setBundledOutput("back",3)
ronoff=1
end

function stop()
rs.setBundledOutput("back",2)
sleep(2)
rs.setBundledOutput("back",0)
ronoff=0
end

function ui()
getstates()
drawdisp()
print(""..euflow)
term.setCursorPos(11,6)
write("Enter choice: ")
end

function run()
ui()
x=io.read()
if x==1 and ronoff==0 then
  start()
  elseif x==1 and ronoff==1 then
  stop()
end
run()
end

run()

It starts, goes to running the run() function and giving me the output of the ui() function on the ingame screen.
But as i type 1 and press enter i get:

startup:23: attempt to call boolean
line 23 is:

if ronoff==0 and ron()==false then

Strange thing is, that the function this line is in, getstates(), should have been used by now, and doesn't give an error there.
after typing 1 and pressing enter it shouldn't even use that function.

I really don't know why i get that error :D/>/>

Every help is appreciated!
Luanub #2
Posted 20 May 2012 - 10:58 AM
Your returning the var ison instead of a bool in the function ron(). Try changing it to this and see if it helps.


function ron()
if colors.test(redstone.getBundledInput("back"), 64) then
return true
else return false end
end

Also you can test the bundled input a cleaner then what you are doing with rs.testBundledInput("side", colors.whatever)


function ron()
if rs.testBundledInput("back", colors.pink) then
return true
else return false end
end
coolmodi #3
Posted 20 May 2012 - 12:40 PM
Thanks, now i got it working with that!

Apparently i was too tired to see some of the major flaws in the code xD
I just wrote it completly new and now its working so far.

But

rs.testBundledInput("back", colors.pink)
only is true when ONLY the color pink/64 is found, at least thats what i know.
Therefor i use

colors.test(redstone.getBundledInput("back"), 64)
to check if the color pink is one of the active colors.
correct me if i'm wrong :P/>/>
Luanub #4
Posted 20 May 2012 - 12:50 PM
testBundledInput test to see if that color is turned on, if it is returns true, if not returns false. It doesn't matter if any other colors are on or not, it only looks at the color that you put in the command.
my_hat_stinks #5
Posted 20 May 2012 - 01:47 PM
But

rs.testBundledInput("back", colors.pink)
only is true when ONLY the color pink/64 is found, at least thats what i know.
Therefor i use

colors.test(redstone.getBundledInput("back"), 64)
to check if the color pink is one of the active colors.
correct me if i'm wrong :P/>/>

colors.pink is just a variable storing the value 64, both those lines would work the exact same way (Unless there's some modifications to the colors table :D/>/>)