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

attempt to call nil error

Started by Soulack, 12 September 2013 - 09:43 AM
Soulack #1
Posted 12 September 2013 - 11:43 AM
Can´t open an own topic, so i ask here if that okay :)/>
I´m german, so i used german words in the code, sorry.

problem:
attempt to call number
or
attempt to call nil

server
code is really big, so just an example

function sx() -- function to set x
write("X: ")
x1 = tonumber(read())
if x1 == "x" then
os.reboot()
elseif not tonumber(x1) then
print("Es wurde keine Zahl eingegeben!")
sleep(1)
sx()
end
end

Same for y and z


function h()
write("H: ")
h1 = tonumber(read())
if h1 == "x" then
os.reboot()
elseif not tonumber(h1) then
print("Es wurde keine Zahl eingegeben!")
sleep(3)
h()
end

end

shell.run("clear")
print("--------------")
print("I Beenden I")
print("--------------")
print("")
print("-----------")
print("I Weiter I")
print("-----------")
daten()

while true do
mouse()

if y >= 5 and y <= 7 and x >= 1 and x <= 10 then -- Position Button 1
shell.run("clear")
daten()
print("")
sx()
sy()
sz()
h()

rednet.send(id, "satellit")
a, msg, b = rednet.receive(15)
print(msg)
rednet.send(id, x1)
rednet.send(id, y1)
rednet.send(id, z1)
rednet.send(id, h1)
a, msg, b = rednet.receive(15)

receiver
only example.

if hauptpc == true then
local x1, y1, z1 = gps.locate(10)
if x1 == nil then
                rednet.send(id, "no signal")
os.reboot()
else
rednet.send(id, "koords")
a, setx, b = rednet.receive()
a, sety, b = rednet.receive()
a, setz, b = rednet.receive()
a, seth, b = rednet.receive()

if not tonumber(setx) or not tonumber(sety) or not tonumber(setz) then
rednet.send(id, "error")
os.reboot()
end

example:
type in 1500 47 20 30 -> and get "error"
If i use
height = seth - sety
I get attempt to compare nil

Anyone can help me? :S
Lyqyd #2
Posted 12 September 2013 - 12:43 PM
Split into new topic.

You really need to go read ALL of the sticky posts, both of the global ones and the New Members and Before Asking Questions topics here in Ask a Pro. If you had done this, you wouldn't have posted your question in the wrong place.
Soulack #3
Posted 12 September 2013 - 06:12 PM
Found the problem in the code, my turtle receives wrong information ;)/>