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

Need Help Stuck On Part Of Code

Started by Dejected, 01 October 2013 - 04:51 PM
Dejected #1
Posted 01 October 2013 - 06:51 PM
I need help I run the code and get to

rednet.open("right")
host = tonumber(18)
x,y,z = gps.locate()
rednet.send(host,x)
rednet.send(host,y)
while true do
id,message = rednet.receive()
while id ~= host do
   id,message = rednet.receive()
end
print(message)
if message == move then
   id,message = rednet.receive()
   while id ~= host do
	 id,move = rednet.receive()
   end
   print(move) <--- here
   tonumber(move)
   move = move + 1
   print(move)
   for i = 1,move do
	 x,y,z = gps.locate()
	  if x ~= 30 then
	    turtle.forward()
	    turtle.forward()
	    turtle.forward()
	  elseif x == 30 then
	    turtle.forward()
	    turtle.forward()
	    turtle.turnRight()
	  end
    end
  end
end
Well I assume that's where I get because the last thing that is printed it the number that is sent
Yevano #2
Posted 01 October 2013 - 07:57 PM
You need to assign move to the returned value of tonumber like this:

move = tonumber(move)

Functions cannot actually modify the arguments given to them, because they get a copy rather than a reference.
immibis #3
Posted 02 October 2013 - 01:36 AM
Also, this:

if message == move then
checks if the contents of the variable called message is equal to the contents of the variable called move - but you don't have a variable called move.
Is that a mistake?
MKlegoman357 #4
Posted 02 October 2013 - 08:56 AM
host = tonumber(18)

You don't need tonumber because 18 is already a number.
Dejected #5
Posted 02 October 2013 - 09:54 AM
Also, this:

if message == move then
checks if the contents of the variable called message is equal to the contents of the variable called move - but you don't have a variable called move.
Is that a mistake?
You were correct I forgot the quotation marks