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

train: 2: attempt to index ? (a number value)

Started by mark332, 20 March 2013 - 07:21 AM
mark332 #1
Posted 20 March 2013 - 08:21 AM
I've got a problem with my computercraft program, I always get an error Like this: "train |2| attempt to index (a nuber value?)" and/or
"train |22| attempt to index (a nuber value?)"

I've also tryed the decimal-code instead of colors.<color> but I won't work.. so now I have to ask a pro, whats wrong with my code.
! Please notice, I'm still in Minecraft 1.4.7, because I'm playing MindCrack !


goal = "NPC-1"
colors = colors.combine(32)
rs.setBundledOutput("back", colors)

function DoNotStart()
term.setTextColor(colors.red)
print(" ")
print("Please don't drive!")
print(" ")
print("Incoming Train!")
colors = colors.subtract(colors, colors.lime)
rs.setBundledOutput("back", colors)
end
function  AbleTS()
term.setTextColor(colors.lime)
print(goal)
colors = colors.combine(colors.lime)
rs.setBundledOutput("top", colors)
end
function checkH()
check = rs.getBundledInput("back")
if colors.test(check, colors.white) then
checkIn = 1
elseif not colors.test(check, colors.white) then
checkIn = 0
else
checkIn = 3
end
end
function printDir()
if checkIn ==  1 then
DoNotStart()
elseif checkIn == 0 then
AbleTS()
else
	error("Fatal error, please contact the .Admins.!")
end
end
while true do
sleep(0,5)
term.clear()
term.setCursorPos(1,1)
checkH()
printDir()
end

And: Please excuse missplellings, I'm from Germany and not so good in english. ;)/>
Edited on 20 March 2013 - 07:23 AM
Lyqyd #2
Posted 20 March 2013 - 08:44 AM
Split into new topic.

You can't use a variable called "colors" if you expect to keep being able to use the colors API. When you set the value of the variable "colors", you're overwriting the colors API. Change your variable name.
remiX #3
Posted 20 March 2013 - 08:45 AM
colors = colors.combine(32)

colors.combine needs a variable with current colors and another color:


-- Let's say the left side has colors.red, colors.blue and colors.orange activated
c = rs.getBundledOuput( 'left' )

-- Now lets combine colors.white
c = colors.combine( c, colors.white )

EDIT: Oh yeah, as lyqyd said don't overwrite the api xD
( Just changed mine now )
mark332 #4
Posted 21 March 2013 - 02:29 AM
thanks for you answers, I'll try it out and report to you :)/>
mark332 #5
Posted 22 March 2013 - 12:54 AM
Thank you this code has been accepted by my computer.

Thank you very much :)/>