Jump to content




Help with moving system


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

#1 ThePizzaBoy

  • New Members
  • 2 posts

Posted 29 June 2013 - 02:02 PM

Title: Help with moving system

I made a little movement system for turtles and it works fine until it gets to the turn function. the error is that it is expecting 'then' on line 36 when it is clearly there i dont know what else to do.

function forward()
  print("How far do you want to go forward?")
  local i = read()
  for f = 1, i, 1 do
    turtle.forward()
  end
end

function up()
  print("How far do you want to go up?")
  local i = read()
  for u = 1, i, 1 do
    turtle.up()
  end
end

function back()
  print("How far do you want to go back?")
  local i = read()
  for b = 1, i, 1 do
    turtle.back()
  end
end

function down()
  print("How far do you want to go down?")
  local i = read()
  for d = 1, i, 1 do
    turtle.down()
  end
end

function turn()
  print("Do you want to turn right, left or none?")
  local input = read()
  if input = right then
    print("How many rotations to the right?")
    local i = read()
    for r = 1, i, 1 do
	  turtle.turnRight()
    end
  end
  if input = left then
    print("How many rotations to the left?")
    local i = read()
    for l = 1, i, 1 do
	  turtle.turnLeft()
    end
  end
  if input = none then
  end
end
turn()
forward()
up()
back()
down()


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 29 June 2013 - 02:14 PM

Split into new topic.

== is the comparison operator, = is the assignment operator. Use the comparison operator when you're comparing two values in an if statement.

#3 Apfeldstrudel

  • Members
  • 161 posts

Posted 30 June 2013 - 08:26 AM

To clarify,
if x=17 then
  do stuff
end
This wont work, you are saying "if 17 then do this"- that sentence doesnt make sensw to humans... Nor to computers.
if x==17 then
  do stuff
end
This will work, you are now saying "if x is 17 then do this."

#4 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 30 June 2013 - 08:41 AM

read() returns a string, but you need a number for the for-loops.
With this snippet you keep asking until the string is a number:
local var = nil
repeat
   var = tonumber(read())
until var


#5 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 30 June 2013 - 08:46 AM

i corrected some things:
Spoiler
this code should work, but it hasn`t been tested yet.

#6 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 30 June 2013 - 09:58 AM

if input = "none" then--if you put an if statement inside a script, it needs to actually do something
   sleep(10)
  end

More assigning instead of testing.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users