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

ICBM - Trying to call a NIL value.

Started by jushymaso222, 03 March 2018 - 08:14 AM
jushymaso222 #1
Posted 03 March 2018 - 09:14 AM
I have been working for at least 5 or 6 hours now on an overall missile control system with ICBM. I did everything right except for the slave computers that connect to the silos. I have been trying to fix my code for the slave computer over and over again for about 30 minutes even looking online for help. I am trying to make a slave computer that continuously checks to see if the master computer, id 28, sends a serialised message to it. I then is supposed to unserialise it and then use the two variables that were serialised to set the target of the missile and then launch it. Everything it comes back with Failed to call a nil value. Please help me! I'm stuck! Thank you in advance.

rednet.open("left")
local csx = 0 --X co-ordinate
local csz = 0 --Z co-ordinate
local icbm = peripheral.wrap("right") --Link to the silo controller
while true do
id, msg = rednet.receive(id, msg) --Receive command from master
table = textutils.unserialise(msg) --Analyze msg
csx = table[1] --change x co-ordinate to the one sent
csz = table[2] --change z co-ordinate to the one sent
icbm.setTarget(csx,0,csz) --Set Target
sleep(1) --yield time
icbm.launch() --launch missile to set target
os.reboot()
end
Bomb Bloke #2
Posted 04 March 2018 - 06:27 AM
The error will include a number, which points you to the line where the problem is occurring.
SuperDyl19 #3
Posted 05 March 2018 - 11:19 PM
The problem might come from the line

id, msg = rednet.receive(id, msg)

This might be a little difficult to notice from the error messages you're getting, but you need to remove the arguments from the rednet.receive() code because they haven't been defined (thus running rednet.receive() with the values nil and nil). The actual parameter for this command is a string value and a number value. You can read more here: http://www.computercraft.info/wiki/Rednet.receive


So, since your code doesn't need to do anything while running the code, you can change the line so the computer just sits there waiting for a message as such:

id, msg = rednet.receive()

rednet.receive() is then going to listen, pausing the code until it gets the message you want. I hope this fixes your problem! If you need any more help and can't figure it out yourself, feel free to ask!
Bomb Bloke #4
Posted 06 March 2018 - 02:55 AM
This might be a little difficult to notice from the error messages you're getting, but you need to remove the arguments from the rednet.receive() code because they haven't been defined (thus running rednet.receive() with the values nil and nil).

Nah, not unless rednet.receive() wanted to "call" its parameters. Lua's actually very flexible when it comes to function arguments - you can pass as few or as many as you like, and it's entirely up to the function itself to figure out if that's appropriate or not.