Title: Problem with a Mining Turtle Lua Source Code
Hello,
I got a Problem with my Mining Program for my Mining Turtle. It would be really nice if you could take a look over it.
I pasted my sourcecode here.
And the tabs in the source code are only for a more clear view over the code. When I use the program in the turtle I delete the tabs.
Thanks a lot.
Regards,
jkhsjdhjs
Problem with a Mining Turtle Lua Source Code
Started by jkhsjdhjs, Aug 30 2013 04:07 PM
5 replies to this topic
#1
Posted 30 August 2013 - 04:07 PM
#2
Posted 30 August 2013 - 04:11 PM
Split into new topic. Oh and you shouldn't delete the tabs. They have no effect on how the program runs and are a great programming practice that you should always use
#3
Posted 30 August 2013 - 04:26 PM
First problem:
You don't have to define variable types. This will suffice:
Second problem, the use of while loops is usually discouraged when you need to do a task a certain number of times. It's much cleaner and generally better logic to use a for loop. Instead of doing this:
You can do this:
Also a note, you'll have to start thinking in terms of 1 instead of 0, because lua tends to favor 1-indexing over 0-indexing.
float x=0, y=0
You don't have to define variable types. This will suffice:
x = 0 y = 0 --# or x = 0; y = 0 --# oor x, y = 0, 0
Second problem, the use of while loops is usually discouraged when you need to do a task a certain number of times. It's much cleaner and generally better logic to use a for loop. Instead of doing this:
i = 1 while i <= 10 do print(i) i = i + 1 end
You can do this:
for i=1, 10 do print(i) end --# for loops also have a step option --# this will print 1, 3, 5, etc. for i=1, 10, 2 do print(i) end
Also a note, you'll have to start thinking in terms of 1 instead of 0, because lua tends to favor 1-indexing over 0-indexing.
#4
Posted 30 August 2013 - 05:31 PM
for i=1, 10 do
print(i)
end
Will this loop repeat 10 times? If yes, I understood this type of loop.
print(i)
end
Will this loop repeat 10 times? If yes, I understood this type of loop.
#5
Posted 30 August 2013 - 05:32 PM
Yes it will.
#6
Posted 30 August 2013 - 05:33 PM
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











