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

[ERROR] I have not idea what's wrong with this

Started by billysback, 09 October 2012 - 04:51 PM
billysback #1
Posted 09 October 2012 - 06:51 PM
Error is "attempted to compare number with string expected, got number"

and the code is

   	 local maxani = splt[5]
		local curani = splt[6]
		if forwards then
			curani = curani + 1
		else
			curani = curani - 1
		end
		if (curani) > (maxani) then
			curani = 1
		elseif (curani) < 1 then
			curani = maxani
		end

5 and 6 are the correct values for those two variables, I double checked by making the game print their values to me.

the brackets were added in as an attempted fix, the same error is returned with or without them.

the error is on line 214 [ elseif (curani) < 1 then ]
remiX #2
Posted 09 October 2012 - 07:24 PM
When you do elseif (curani) < 1 then
is curani a number or string at that point?
billysback #3
Posted 09 October 2012 - 08:12 PM
a number, they are both numbers from initialization unless you can see something in that code which makes them otherwise.
BrolofTheViking #4
Posted 09 October 2012 - 09:28 PM
is Splt a table?
In which case, when you add values to it, are you adding them as strings?
try doing maxani = toNumber(splt[5]) and curani = toNumber(splt[6])
OmegaVest #5
Posted 09 October 2012 - 09:29 PM
Wait, brackets? Or parentheses? If it's brackets, it might be looking for a string instead of a number (which would make sense, given the error says it is, in fact, looking for a string where a number is being given).


Further, have you tried tonumber-ing them. It should not make a difference if they are numbers, but I've seen CC do some amazingly stupid things, and doing something equally stupid usually fixes it.
billysback #6
Posted 09 October 2012 - 09:53 PM
thanks, putting tonumber(splt[5]) and tonumber(splt[6]) worked,

@BrolofTheViking
there isn't a capital N in tonumber :P/>/>