This may be considered a revive of an old topic, but it wasn't quite what I was looking for... I found a topic about a turtle repeating a specific amount of times, but it wasn't in the context that I was looking for, as I want a code to repeat 5 times. Any ideas on how to do this? If there is a post with this topic and context, please give a link?
E.G: shell.run("go down") X5
thats essentially what I want it to do. I don't want to write the same string over and over again as if it is in high quantities, it'll get pretty boring. This is for the current project and future reference
2
7 replies to this topic
#1
Posted 29 August 2015 - 03:15 PM
#2
Posted 29 August 2015 - 04:02 PM
Since you're already using the command, this should work:
Though it's generally a bad idea to use shell.run for simple tasks like this, use the turtle api instead. You can use a for loop to repeat the action:
shell.run("go down 5")
Though it's generally a bad idea to use shell.run for simple tasks like this, use the turtle api instead. You can use a for loop to repeat the action:
for i=1,5 do turtle.down() end
#3
Posted 29 August 2015 - 05:17 PM
Ah! I see! well, i shall be using the turtle API instead from now on for tasks like this!! Thx for the help, but for future reference, what does the i=1,5 mean? ik it means to repeat x amount of times but what does the I part mean? if you could tell me that that'd be fantastic!! if not, then thx for the help anyway!!!
#4
Posted 29 August 2015 - 05:37 PM
It's a numeric for loop. 'i' can be any variable you want, and will be local to the scope of the loop. It will contain the current iteration:
for i = 1, 5 do print( "i is now: " .. i ) end
#5
Posted 30 August 2015 - 05:19 PM
KingofGamesYami, on 29 August 2015 - 05:37 PM, said:
It's a numeric for loop. 'i' can be any variable you want, and will be local to the scope of the loop. It will contain the current iteration:
sooooooo your saying that it defines the amount of times to loop? right?
#6
Posted 30 August 2015 - 06:45 PM
Sort of. i = 1 means the loop will start at 1. The second value, 5, means it will iterate until i >= 5. The lack of a third value means the loop will default to +1 increments. If you add a third value, you could have it count by different increments, including negative numbers.
Edited by KingofGamesYami, 30 August 2015 - 06:46 PM.
#7
Posted 07 September 2015 - 03:42 AM
Output:
i is now: 1
i is now: 2
i is now: 3
i is now: 4
i is now: 5
i is now: 1
i is now: 2
i is now: 3
i is now: 4
i is now: 5
#8
Posted 30 October 2015 - 03:30 PM
KingofGamesYami, on 30 August 2015 - 06:45 PM, said:
Sort of. i = 1 means the loop will start at 1. The second value, 5, means it will iterate until i >= 5. The lack of a third value means the loop will default to +1 increments. If you add a third value, you could have it count by different increments, including negative numbers.
ohhhh right, k, i get it now! thx
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users