attempt to perform arithmetic on a nil value

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

attempt to perform arithmetic on a nil value

Post by Doctory »

hi guys, i have an error: attempt to perform an arithmetic on a nil value
it happends when you type a number a9b, where a+b is 7
for example, if you type 196 (this is a9b number, 9 is its middle number and its first and last number when added equal to 7) it throws this error

numbers to replicate the error: 196, 394, 592, 790
if you want to know what i was doing here, it was the reverse and add thing from this video:

palindrome.love
(604 Bytes) Downloaded 75 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: attempt to perform arithmetic on a nil value

Post by micha »

The error occurs in line 51 of your code.
It happens when you call the function "rev" on a number that is too large.
If you insert the lines

Code: Select all

print(cur)
print(rev(cur))
right before line 51 you will see that the value of cur is "1.595479779756e+14". If you convert it to a string and reverse it, then it contains the plus-sign. An converting this to a number returns nil.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: attempt to perform arithmetic on a nil value

Post by Doctory »

can i write the actual full number in any way?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: attempt to perform arithmetic on a nil value

Post by micha »

I had to look it up myself. Here is the solution: http://stackoverflow.com/questions/1133 ... c-notation
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: attempt to perform arithmetic on a nil value

Post by Doctory »

much thanks
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests