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

Not sure what i've missed here.

Started by Tolarn, 22 July 2015 - 05:19 PM
Tolarn #1
Posted 22 July 2015 - 07:19 PM
I've moved through most of my own bugs but this one has me stumped.
My idea was to take a timer I saw on https://www.youtube.com/watch?v=IR-e1D4TIUU and have it trigger my reed farming turtle and have it display on a monitor on the left of the turtle.

Asside from my math being wrong I can't find my syntax error or whatever is gumming up. Any help would be much appreciated. Also i'm very new to this.

Getting ')" expected on line 18.

http://pastebin.com/kRxnUjmb

Codelocal mon = peripheral.wrap("left")
local m = 33
local s = 0
repeat
if m > 0 then
if s > 0 then
s = s - 1
else
s = 59
m = m - 1
end
else
if s > 0 then
m = m - 1
end
end

mon.write("m..":"s.." )

sleep(60)

if m == 0, s == 0 then

print("Turtle is farming")

turtle.select(1)
turtle.refuel(1)
turtle.up()
turtle.up()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
turtle.select(2)
turtle.drop()
os.sleep(2000)
i= i + 1
until i == 5
Balthamel #2
Posted 22 July 2015 - 08:00 PM
concatenating works to combine strings as follows
variable txtSrting1 and txtString2 contain strings "Number" and "Letter" respectivly

print("this is string 1 "..txtString1.." : and this is string 2 "..txtstring2)
would print
this is string 1 Number : and this is string 2 Letter
Zenon #3
Posted 22 July 2015 - 08:40 PM
You cant do this:

mon.write("m..":"s.."
I dont know what youre trying to do there, but if you want to combine things do this:

mon.write(var1.."string"..var2.."string2)
Or something of the like
H4X0RZ #4
Posted 22 July 2015 - 08:53 PM
As the others said, you messed up concatenating the two strings.

.. acts as something like glue. It allows you to stick two or more things together, building something like a chain.

print("This ".." is ".." a ".." test ")
--> This is a test
This could be translated to:
1. Put " is " at the end of the string "This ".
2. Then put " a " at the end of the string you got from 1.
3. Afterwards put " test" at the end of the string you got from 2.
4. Print out the string from 3.

You can concatenate almost anything, you just have to "tostring" it before you concatenate.

For tables there is a special function called table.concat. It allows you to concatenate every entry in the table, and takes two arguments.


local tbl = {"This","is","a","test"}
print(table.concat(tbl, " ") -- The first argument is the table you want to "concatenate", the second argument is the string you want to put between every element.
--> This is a test


Then there is something about your code, which is not the concatenation:

You can (and should) use loops, instead of calling the functions over and over. It makes your code much more readable, and you can modify it more easily. Also it makes you code (most of the time) smaller.

A simple for loop allows you to run a specific block of code multiple times.

for i = 1,10,1 do
  turtle.forward()
end
This makes the turtle go forward 10 blocks. Note that i is just a normal variable name, and you can change it to whatever you like, but I think i is the most used (if you have loops inside of loops, the convention is just increasing the letter by one (i.e. i,j,k,l), i believe). The first number (e.g. 1) is the starting point, the second one (e.g. 10) the ending point. The third one (e.g. 1) is the step you want to increase with. Normally it is 1, and then you can leave it out, but if you i.e. want to loop backwards (10,9,8,7… instead of …7,8,9,10) you have to change the step (in my example you have to set it to -1). Also you can access i inside the loop, and it will change on every iteration.

for i = 1,10 do
  print(i)
end
will output the numbers from 1 to 10 and

for i = 10,1,-1 do
  print(i)
end
will output the the numbers from 10 to 1.

Then there is the while loop. It allows you to execute something as long a variable is true. a well known usage is the "infinite loop" which allows you to run code, until it is forcefully terminated, or you "break" it.

This loop will execute infinitely because true is always true.

while true do
  turtle.forward()
end
Edited on 22 July 2015 - 07:05 PM
Tolarn #5
Posted 23 July 2015 - 11:33 PM
So right now I've got this working and scrapped the timer and display for the moment. Which is still pretty messy.

http://pastebin.com/gxbnVYJYprint("Turtle is farming")
while true do
turtle.select(1)
turtle.refuel(1)
turtle.up()
turtle.up()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
turtle.select(2)
turtle.drop()
os.sleep(3)
end
Tolarn #6
Posted 24 July 2015 - 03:00 AM
So using advice from before I've updated my code. Figured out how to use functions and the loops. not sure if I made it smaller but definitely easier to upgrade if I need to.

Here is the revised version. I completely changed the path to be more efficient in the programming and make it easier to upgrade since I may make larger reed farms in the future.

http://pastebin.com/0uAT0NL4#
Spoilerprint("Turtle is Farming")

local function farm() – Turtle moves forward and digs whats in front of him
for t = 1,7,1 do
turtle.dig()
turtle.forward()
end
end

local function right() – makes right turn
for r = 1,1,1 do
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
end

local function left() – makes left turn
for v = 1,1,1 do
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
end

while true do

turtle.select(1)
turtle.refuel(1)
for i = 1,3,1 do
turtle.up()
end

farm()
right()
farm()
left()
farm()
right()
farm()

turtle.turnRight()
for j = 1,3,1 do
turtle.forward()
end
for k = 1,3,1 do
turtle.down()
end

turtle.select(2)
turtle.drop()
turtle.turnRight()
sleep(10) – turtle waits one hour
end

The problem I'm running into with the timer displaying is how I have the turtle setup in the area its setup. I think I can program it now that I understand a little bit more how things work. I just need to figure out how to setup a wireless card to update my timer to a computer that will display the time till it starts farming. Eventually Id like to setup a large monitor with multiple times on it to see multiple timers on different things. Will take a bit more learning and any advice would be welcomed.

Thank you for all the information. If I get stuck again I know were to go =)