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

Can't tell what is wrong

Started by icecube45, 09 November 2012 - 03:33 PM
icecube45 #1
Posted 09 November 2012 - 04:33 PM

x = 0
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
  until local g == width
end
function layor()
oneline()
end

print("Enter hight")
hight = read()
print("Enter Width")
width = read()
oneline()
end
i get unexpected symbol.. i can't find where tho any help would be great, this is just the start of a program

i am fairly new at lua
Luanub #2
Posted 09 November 2012 - 04:53 PM
You don't need the end at the end of the code.

You also don't need the local in the until statement


x = 0
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
  until g == width
end
function layor()
oneline()
end

print("Enter hight")
hight = read()
print("Enter Width")
width = read()
oneline()

icecube45 #3
Posted 09 November 2012 - 05:03 PM
thank you, ill test
icecube45 #4
Posted 09 November 2012 - 05:06 PM
it worked. kind of
now my turtle will just go in a strait line forever
Kingdaro #5
Posted 09 November 2012 - 05:07 PM
You're not adding anything to g during the repeat loop in the oneline function, so it never reaches width.
icecube45 #6
Posted 09 November 2012 - 05:12 PM
o! i should have seen that, thanks
EDIT: still isnt working

x = 0
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
   g = g+1
  until g == width
end
function layor()
oneline()
end

print("Enter hight")
hight = read()
print("Enter Width")
width = read()
oneline()
Luanub #7
Posted 09 November 2012 - 05:27 PM
The read is probably setting the input as a string and not a number Try this.

print("Enter hight")
hight = tonumber(read())
print("Enter Width")
width = tonumber(read())

icecube45 #8
Posted 09 November 2012 - 05:44 PM
works now, thanks, ill continue this, so stick around
icecube45 #9
Posted 09 November 2012 - 05:54 PM
ima back, i get unexpected symbol again

x = 0
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
   g = g+1
  until g == width
end
function layor()
repeat
  oneline()
  turtle.turnRight()
  turtle.dig()
  turtle.forward()
  x = x+1
  oneline()
  turtle.turnLeft()
  turtle.dig()
  turtle.forward()
  x = x+1
until x = width/2
end

print("Enter hight")
hight = tonumber(read())
print("Enter Width")
width = tonumber(read())
oneline()
Kingdaro #10
Posted 09 November 2012 - 06:15 PM
In your layor function:


until x = width/2

The "=" should be "==".


until x == width/2
icecube45 #11
Posted 09 November 2012 - 06:19 PM
o! forgot about that
icecube45 #12
Posted 09 November 2012 - 06:26 PM
The turtle will now not stop digging that first layor

x = tonumber(0)
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
   g = g+1
  until g == width
end
function layor()
repeat
  oneline()
  turtle.turnRight()
  turtle.dig()
  turtle.forward()
  turtle.turnRight()
  x = x+1
  oneline()
  turtle.turnLeft()
  turtle.dig()
  turtle.forward()
  turtle.turnLeft()
  x = x+1
until x == width/2
end

print("Enter hight")
hight = tonumber(read())
print("Enter Width")
width = tonumber(read())
layor()
Kingdaro #13
Posted 09 November 2012 - 06:30 PM
If you're using CC versions 1.4 or above, turtles need fuel.

Place some coal, wood, a lava bucket or anything refuelable in the turtle's inventory, and type "refuel" in the console.

You can also refuel automatically from within your programs, if you prefer. There's more info on the wiki.
icecube45 #14
Posted 09 November 2012 - 06:31 PM
im using tekkit, so its not 1.4 the thing is, my turtle will dig like this

XXXXXX
XXXXXX
XXXXXX

Is what it is ment to mine, it mines

XXXXXXXXXXXXXXXXXXXXX….
XXXXXXXXXXXXXXXXXXXXX….
xxxxxxxxxxxxxxxxxxxxxxxxxxxx….
Kingdaro #15
Posted 09 November 2012 - 06:46 PM
Oh, I see what you mean. In your layor() function, it checks to see if x will equal width/2, however there's a chance that you enter in an odd number for width, which, divided by 2, gives a decimal.

So if you enter in 7, width/2 is 3.5.

The script goes:

1.. 2.. 3..

so then we check to see if we're at 3.5, but nope, it just skips it and goes to 4

5.. 6.. 7.. 8.. 9.. 10.. 11…

see what I mean? It's better to check if it's greater than, or equal to a number we don't actually know is going to be whole.

until x >= width/2

that, or just floor it. math.floor() goes down to the next whole number from the current decimal. So 2.1 goes to 2, and 2.9 goes to 2.

until x == math.floor(width/2)
icecube45 #16
Posted 09 November 2012 - 06:49 PM
ok
icecube45 #17
Posted 09 November 2012 - 06:50 PM

x = tonumber(0)
function oneline()
local g = 0
  repeat
   turtle.dig()
   turtle.forward()
   g = g+1
  until g == width
end
function layor()
repeat
  oneline()
  turtle.turnRight()
  turtle.dig()
  turtle.forward()
  turtle.turnRight()
  x = x+1
  oneline()
  turtle.turnLeft()
  turtle.dig()
  turtle.forward()
  turtle.turnLeft()
  x = x+1
until x == math.floor(width/2)
end

print("Enter hight")
hight = tonumber(read())
print("Enter Width")
width = tonumber(read())
layor()
still does it
Kingdaro #18
Posted 09 November 2012 - 06:55 PM
Try the >= symbol then.
icecube45 #19
Posted 09 November 2012 - 07:11 PM
ok