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

game.lua:80: bad argument: int expected, got nil

Started by svennp, 12 March 2012 - 09:13 PM
svennp #1
Posted 12 March 2012 - 10:13 PM
hi, im working on a game that uses redstone input and outputs to redstone torches.

i get an error saying: game.lua:80: bad argument: int expected, got nil

i cant seem to figure out whats wrong :L

its a work in progress, so im not nearly done.

here is the code:
Spoiler



n1 = 0
n2 = 0
n3 = 0
n4 = 0
--
function alloff()

rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.white ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.orange ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.magenta ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.lightBlue ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.yellow ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.lime ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.pink ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.gray ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.lightGray ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.cyan ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.purple ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.blue ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.brown ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.green ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.red ) )
rs.setBundledOutput( "back", colors.combine( rs.getBundledOutput( "back" ), colors.black ) )
rs.setBundledOutput( "bottom", colors.combine( rs.getBundledOutput( "bottom" ), colors.lightBlue ) )
rs.setBundledOutput( "bottom", colors.combine( rs.getBundledOutput( "bottom" ), colors.pink ) )

end
--
function allon()

rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.white ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.orange ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.magenta ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.lightBlue ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.yellow ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.lime ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.pink ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.gray ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.lightGray ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.cyan ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.purple ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.blue ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.brown ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.green ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.red ) )
rs.setBundledOutput( "back", colors.subtract( rs.getBundledOutput( "back" ), colors.black ) )
rs.setBundledOutput( "bottom", colors.subtract( rs.getBundledOutput( "bottom" ), colors.lightBlue ) )
rs.setBundledOutput( "bottom", colors.subtract( rs.getBundledOutput( "bottom" ), colors.pink ) )

end
--
function main()
while true do
if n1 == 0 then
rs.setBundledOutput( "bottom", colors.subtract( rs.getBundledOutput( "bottom" ), colors.lightBlue ) )
event = os.pullEvent()
if event == "redstone" then
if rs.testBundledInput("bottom", colours.lime) then
os.reboot()
elseif
rs.testBundledInput("bottom", colours.white) then
n2 = n2 + 1
elseif
rs.testBundledInput("bottom", colours.orange) then
n2 = n2 + 2
elseif
rs.testBundledInput("bottom", colours.magenta) then
n2 = n2 + 3
end
n1 = 1
event = os.pullEvent()
rs.setBundledOutput( "bottom", colors.combine( rs.getBundledOutput( "bottom" ), colors.lightBlue ) )
end
elseif n1 == 1 then
rs.setBundledOutput( "bottom", colors.subtract( rs.getBundledOutput( "bottom" ), colors.pink ) )
event = os.pullEvent()
if event == "redstone" then
if rs.testBundledInput("bottom", colours.lime) then
os.reboot()
elseif rs.testBundledInput("bottom", colours.gray) then
n2 = n2 + 1
elseif rs.testBundledInput("bottom", colours.lightGray) then
n2 = n2 + 2
elseif rs.testBundledInput("bottom", colours.cyan) then
n2 = n2 + 3
end
n1 = 0
event = os.pullEvent()
elseif n2 == 16 then
break
end
end
end
end

-- done with functions

while true do
print ("counter: "..n1)
print ("display: "..n2)
event = os.pullEvent()

if event == "redstone" then
if rs.testBundledInput("bottom", colours.yellow) then
alloff()
sleep(1)
main()
elseif rs.testBundledInput("bottom", colours.lime) then
os.reboot()
end
end
end

MysticT #2
Posted 12 March 2012 - 10:55 PM
You are using the colours API, not the colors API, they are the same but have a little difference: the names.
In colours API it's grey, not gray.
Change that and it should be fixed :mellow:/>/>
svennp #3
Posted 13 March 2012 - 01:16 PM
thanks!
tried it and it works now :mellow:/>/>