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

[Error] Attempt to call nil

Started by Enderman_7, 26 January 2014 - 05:38 AM
Enderman_7 #1
Posted 26 January 2014 - 06:38 AM
Hello
I want my computer to output a redstone signal of 15 to the right if it gets a signal of 15 on the left
And by the way I'm a total newcomer at programming

So here's the code:

local r=redstone.getAnalogInput("left")
if r == 15 then
redstone.setAnalogOutput("right", 15)
end
squirrel_killer #2
Posted 26 January 2014 - 04:09 PM
Do you only want something to happen at a redstone level of 15 and nothing else? I don't understand what this is asking personally.
surferpup #3
Posted 26 January 2014 - 04:58 PM
That code should run. Post all of your code if you continue to have trouble.
TechMasterGeneral #4
Posted 26 January 2014 - 07:59 PM
make sure when you declare the variable there is a space on both sides of the "="… if that doesn't work please post the code
Bomb Bloke #5
Posted 26 January 2014 - 08:32 PM
Assuming this DOES account for all the code in your script, then odds are you've overwritten the redstone API.

Normally "redstone" represents a table filled with functions (eg "getAnalogInput", "setAnalogOutput", etc). But if you do this:

redstone = 12

… then suddenly that table's gone, replaced with the number "12". Hence "redstone.getAnalogInput" no longer points to a function in a table, but to nil. Hence "redstone.getAnalogInput()" would "attempt to call nil".

Also bear in mind that unless you specially declare your own local version of "redstone", this problem won't just persist "until your script ends" - it'll persist until the computer reboots. Hence you may well've "triggered" this problem in a script you ran before this one.
surferpup #6
Posted 26 January 2014 - 10:26 PM
make sure when you declare the variable there is a space on both sides of the "="… if that doesn't work please post the code

There is no requirement of a space. These lines of codes are equivalent:


a=12
a = 12
a =12
a= 12

Please check your solution lua crawler. The advice you offered is in fact erroneous.

Bomb Bloke raises an excellent point. However, without seeing the rest of your code, we cannot be certain of anything.
Edited on 26 January 2014 - 09:27 PM
TechMasterGeneral #7
Posted 28 January 2014 - 11:48 AM
make sure when you declare the variable there is a space on both sides of the "="… if that doesn't work please post the code

There is no requirement of a space. These lines of codes are equivalent:


a=12
a = 12
a =12
a= 12

Please check your solution lua crawler. The advice you offered is in fact erroneous.

Bomb Bloke raises an excellent point. However, without seeing the rest of your code, we cannot be certain of anything.

I was just putting that out there because I have had a couple problems that were fixed by just making sure there was a space between the "=" or "( "modem_message" ) type stuff…
surferpup #8
Posted 28 January 2014 - 11:49 AM
I do agree that a space on both sides of assignment or comparators makes the code much more readable. But they are unnecessary from an interpreter standpoint.
Edited on 29 January 2014 - 06:58 AM
Bomb Bloke #9
Posted 28 January 2014 - 07:33 PM
… but if you find that a given set of code only works with the space present, then that would be a bug in ComputerCraft and should probably be reported as such. With a specific example, of course. ;)/>

Seriously though, until you've got some evidence to back it up, assume that the spaces aren't required.