Jump to content




Need Help Stuck On Part Of Code


  • You cannot reply to this topic
4 replies to this topic

#1 Dejected

  • Members
  • 48 posts
  • LocationPhiladelphia, Pennsylvania

Posted 01 October 2013 - 05: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

#2 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 01 October 2013 - 06: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.

#3 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 02 October 2013 - 12:36 AM

Also, this:

View PostAzxs0424, on 01 October 2013 - 05:51 PM, said:

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?

#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 02 October 2013 - 07:56 AM

View PostAzxs0424, on 01 October 2013 - 05:51 PM, said:

host = tonumber(18)

You don't need tonumber because 18 is already a number.

#5 Dejected

  • Members
  • 48 posts
  • LocationPhiladelphia, Pennsylvania

Posted 02 October 2013 - 08:54 AM

View Postimmibis, on 02 October 2013 - 12:36 AM, said:

Also, this:

View PostAzxs0424, on 01 October 2013 - 05:51 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users