This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
The's profile picture

[question]help with using shell.run()

Started by The, 25 September 2012 - 09:37 PM
The #1
Posted 25 September 2012 - 11:37 PM
I have a program in which a block of code is executed 10 times, but i want to go to a different program after that is finished. If I include shell.run() before "end," it will only do the stuff i wanted to do 10 times 1 time. So where would i place shell.run()?

local amountOfTimes = 10
for 1,amountOfTimes do
--code
end
GopherAtl #2
Posted 25 September 2012 - 11:45 PM
Your "end" ends the loop, so to run after the loop, you'd put it after end. Putting it before the end was running it IN the loop.
The #3
Posted 25 September 2012 - 11:47 PM
So end puts it in a different "script?"

local amountOfTimes = 10
for 1,amountOfTimes do
--code
end
shell.run("programs")
end
Cranium #4
Posted 25 September 2012 - 11:53 PM
No. "end" just ends the current command like if, for, while, and the such. To have the program run once, do this:

for i = 1,10 do
--other code
end --ends the for loop
shell.run("programs") --run outside of the loop
To run the program 10 times, do this:

for i = 1,10 do
shell.run("programs") --run while INSIDE the loop
end
The #5
Posted 26 September 2012 - 12:09 AM
Wow thanks, that clears up a lot. And, is there a way to use turtle.drop() to drop an entire turtle inventory without have to write code for each inventory space selection?
Cranium #6
Posted 26 September 2012 - 12:18 AM
Sure, fairly simple once you get the idea.

for i = 1,16 do
--"i" is the iterator
--1 and 16 are the start and end points
turtle.select(i)
--we select the slot using the iterator "i"
turtle.drop()
--we drop the items
end
The #7
Posted 26 September 2012 - 12:23 AM
Oh ok, now i understand why we do 1,x when using the for function.