8
u/ImNotADeer Dec 16 '20
As already said by others:
Change your for-loop to
for i = 1, 200 doand if that is the whole program, remember to
endthe for loop at the end.
It would also probably help yourself and others to indent the code correctly:
for i = 1, 200 do
while turtle.detect() do
turtle.dig()
os.sleep(1)
end
...
endAnd last but not least, learn how to ask for help (stackoverflow has a good "guide" on this). Essentially:
Describe what you want the code to do
Describe what the code does
Explain what you have tried so far
Include the error message you get when you try to run the code (if any), this helps by telling you what and where the error is
Format your code (it is much more helpful to include written code rather than an image)
1
u/dragon53535 Dec 16 '20
Changing the for loop does nothing. The for loop is set correctly if albeit redundant for the step variable.
Edit: Didn't see the
is. Apologies, besides that though yeah.
2
u/dragon53535 Dec 16 '20 edited Dec 16 '20
You need to call turtle.forward
Don't listen to the others, your format of a for loop is entirely fine. (Edit: But yeah, change is to =) For loops are formatted
for variable declaraction, max value, step doSetting the step at 1 is implied, so you can omit it. But you don't HAVE to.
In future, please just copy/write the code in text instead of sending a screenshot. This is because as you can tell by the screenshot, not all of your code appears at once. Use Pastebin or similar to post the code and you'll get a lot easier time with help. As well as sending the error, it gives 100% of the information about both what is going wrong, but also where it's going wrong.
That being said, posting here or anywhere should be a last resort. Google the error you get, and see if you can apply the solutions to the code you're using. Proper formatting does help too, for both of our sakes.
2
u/leviathon01 Dec 16 '20
Your code will be alot easier to understand if you follow the Lua Style Guide, specifically the part about indentation.
1
u/OneAgainstAHundred Dec 16 '20
After the first while loop you have:
turtle.forward instead of turtle.forward()
1
u/boxesandcircles Dec 16 '20
Sidenote it's probably better to create an API with auto digging movement functions and use os.loadAPI
1
1
1
u/Benzilla99 Dec 16 '20
I think your first for loop is missing an end at the end of all the statements. Might be easier to write code with atom and send it to your bots using pastebin!
0
Dec 16 '20
[deleted]
1
u/Gasmonk74836 Dec 16 '20
A 4x1 tunnel in galacticraft im new to lua and have been trying to learn all day
2
u/GreenTheRyno Dec 16 '20
We all have to start somewhere, my dude. One tip that I use all the time is to make a function that iterated a variable whenever the turtle is able to move forward.
I'm blanking on the exact code I use (it's been a while), but the pseudocode is "open function; while turtle cannot move forward, turtle.dig; X = X+1; close function". Or I guess you could use a negated "if" statement instead of a "while" loop. The variable iteration is technically optional, but it lets your turtle dead reckon a position very easily.
Either way, it helps keep your tunnels a consistent length when you inevitably run into gravel. Also, functions are the best thing since sliced bread.
0
4
u/Gm_070 Dec 16 '20 edited Dec 16 '20
Pretty sure the problem is the for loop, try