Jump to content

Welcome to FTB Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

ComputerCraft loops! Help?


12 replies to this topic

#1
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

Hey guys, i just started writing code for LUA, and i code a little bit, but could someone either explain the best way to loop a program, or how?

And is there a way to test if it will work too? 

 

Heres what i have

 

Spoiler
 
I love CC, but i want to write my own code now, help is appreciated!

 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#2
ZL123

ZL123

    Me.

  • Administrators
  • 2079 posts
  • Location:Not somewhere where people say a fake location to try to be funny
  • IGN:ZL123
  • Modpack:Private Pack

Haven't used LUA in a bit, but I'll give it a shot...

while i == 15 do
   turtle.up()
   turtle.placeDown()
   if turtle.detect() then
      turtle.forward()
      turtle.placeDown()
   end
end

-ZL123
Hope I helped!

YT: http://youtube.com/ZL234
Twitter: https://twitter.com/ZL234


#3
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

Im going to try that, now.


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#4
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

sorry, i need it to detect if there is a block ahead, and if there is, mine it, if not, go forward sooo how might one do that? this? 

Spoiler


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#5
ZL123

ZL123

    Me.

  • Administrators
  • 2079 posts
  • Location:Not somewhere where people say a fake location to try to be funny
  • IGN:ZL123
  • Modpack:Private Pack
while i == 15 do
   turtle.up()
   turtle.placeDown()
   if turtle.detect() then
      turtle.dig()
   else
      turtle.forward()
   end
   turtle.placeDown()
end

-ZL123
Hope I helped!

YT: http://youtube.com/ZL234
Twitter: https://twitter.com/ZL234


#6
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

HA! else statements, duh. i use those with javascript. lmme try.


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#7
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

Well, that didnt work. It just doesnt do anything, i type new hit enter and it doesnt do anything at all, its fueled up and everything. Do i need to tell it to select a stack of items? or..


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#8
ZL123

ZL123

    Me.

  • Administrators
  • 2079 posts
  • Location:Not somewhere where people say a fake location to try to be funny
  • IGN:ZL123
  • Modpack:Private Pack

You need to set i's variable before that...

Like you did originally.


-ZL123
Hope I helped!

YT: http://youtube.com/ZL234
Twitter: https://twitter.com/ZL234


#9
dgelessus

dgelessus

    Advanced Member

  • Administrators
  • 1424 posts
  • IGN:dgelessus
  • Modpack:FTB Tech World 2
What are you trying to use i for anyway? If you want to execute everything 15 times, you probably want a for loop, like this:
for i=1,15 do
  turtle.up()
  turtle.placeDown()
  if turtle.detect() then
    turtle.dig()
  else
    turtle.forward()
  end
  turtle.placeDown()
end

  • ZL123 likes this

#10
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

im trying to take the fuss out of creating these


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#11
dgelessus

dgelessus

    Advanced Member

  • Administrators
  • 1424 posts
  • IGN:dgelessus
  • Modpack:FTB Tech World 2

Fuel up and run "excavate 64" :P


  • ZL123 likes this

#12
DiamondDoctor

DiamondDoctor

    Advanced Member

  • Validating
  • PipPipPip
  • 411 posts
  • Location:On this Plane Of Existence..?
  • Modpack:FTB Monster

so much slower lol


 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Did i help? If so, click that like button! (And then, click Here! This is a feedback poll! Help me Help you and others!) (Stalk me here on the forums!)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bored? Watch these!(-IN THE FACE-...-DADADAOOMSDAY-...-Krieg-...-NFLBLR-...-NFLBLR2-...-Fosko-)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

"Speak softly and carry a diamond sword"-Me                                                                                                                                                                                            

Punching trees, falling off cliffs, punching grass... Now that i think of it, Minecraft sounds painful.                                                                                                 

The Word of the Week isIndefatigable!

Signature now with 89.6% more COLOR!                                                                                                              

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-DiamondDoctor

-For anyone interested, please, please, please check out my mod, AnyUtil, and post suggestions!

 

 


#13
hannoman

hannoman

    Member

  • Contributor
  • PipPip
  • 29 posts
  • Modpack:FTB Unleashed

What are you trying to use i for anyway? If you want to execute everything 15 times, you probably want a for loop, like this:

for i=1,15 do
  turtle.up()
  turtle.placeDown()
  if turtle.detect() then
    turtle.dig()
  else
    turtle.forward()
  end
  turtle.placeDown()
end

 

As degelessus did a great job with the syntax, thats probably not the behaviour you want. In a 1x1 shaft this code will build a vertical pillar of size 15, while clearing the neighbouring pillar. And in the open it will build a staircase. ^^

 

If you just want code to let the turtle move/mine through blocks, it's as easy as:

while true do
   turtle.dig()
   turtle.forward()
end

  • ZL123 likes this



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users