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

button:40: attempt to perform arithmetic __add on number and nil

Started by Nic, 19 August 2016 - 11:07 PM
Nic #1
Posted 20 August 2016 - 01:07 AM
Hey, so i'm making a program that controls my dig reactor in my base and i wanted to use a advanced screen. I downloaded direwolf20's button API and when I implement it into my code i get this error.
button:40: attempt to perform arithmetic __add on number and nil
I also downloaded his demo program and tried it and i got the same error. I have a monitor that is connected with a wired modem (monitor_1).
I thought it might have been with the api not finding a monitor so i removed the first 8 lines of the api and replaced it with

local mon = peripheral.wrap("monitor_1")
but that didn't work, im currently lost on what to do. Thanks in advance

my code : http://pastebin.com/95qYfEiw
**note that at one point the monitor was monitor_0**
Bomb Bloke #2
Posted 20 August 2016 - 01:14 AM
Seems the copy of the button API you've linked is not the copy you're using. The error claims addition is being performed on line 40, but the paste shows that line to be empty.
Nic #3
Posted 20 August 2016 - 03:20 AM
Im sorry the when i use that one its line 47. It was line 40 when i replaced the first 8 lines with

local mon = peripheral.wrap("monitor_1")
Bomb Bloke #4
Posted 20 August 2016 - 08:21 AM
Line 47:

local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)

So either bData.ymin or bData.ymax is nil.

Values are set by setTable(), which expects seven arguments: name, func, param, xmin, xmax, ymin, ymax.

But in the scripts, you only call it with six; for example, in your one on line five:

button.setTable("Stop", alarmToggle, 1, 10, 10, 12)

Seems you're missing the parameter for your function. If you don't want to pass one, then just add "nil" to the argument list:

button.setTable("Stop", alarmToggle, nil, 1, 10, 10, 12)

Note that you can't reliably pass the "alarmToggle" function pointer before you define it!