Jump to content




Problem with a Mining Turtle Lua Source Code


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

#1 jkhsjdhjs

  • Members
  • 3 posts

Posted 30 August 2013 - 04:07 PM

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

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

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 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 30 August 2013 - 04:26 PM

First problem:
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 jkhsjdhjs

  • Members
  • 3 posts

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.

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 30 August 2013 - 05:32 PM

Yes it will.

#6 jkhsjdhjs

  • Members
  • 3 posts

Posted 30 August 2013 - 05:33 PM

Ah, ok thank you all very much ;)

EDIT: Yeah, it's working :D
Here's the final source code.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users