2 posts
Posted 25 April 2016 - 11:53 PM
i have a fairly basic digging program that lookes something like this.
shell.run('clear')
print("how many blocks should i go down?")
local x = io.read()
for i = 1, x do
CheckFuel()
Mine()
Stairs()
end
Yes i have functions setup for Mine() Stairs() CheckFuel() and Torch(). (didnt inclue because i wanted this post to stay short and simple.)
my question is how do i make it so every 5 loops it will send Torch()?
7083 posts
Location
Tasmania (AU)
Posted 26 April 2016 - 12:58 AM
Inside the loop, you could add a check:
if x % 5 == 0 then Torch() end
… where % is the modulus operator, returning the remainder of x divided by 5, in this instance.
756 posts
Posted 26 April 2016 - 12:59 AM
Inside the for loop, add if i % 5 == 0 then Torch() end
i%5 == 0 basically means the statement is going to be true when i is a multiple of 5.
Edited on 26 April 2016 - 12:31 AM
7083 posts
Location
Tasmania (AU)
Posted 26 April 2016 - 01:47 AM
Gah, yes, it would need to be "i", not "x".
2 posts
Posted 26 April 2016 - 02:07 AM
Thanks! Worked Great :D/>
15 posts
Location
somewere in Belgium
Posted 01 May 2016 - 02:08 AM
i have a fairly basic digging program that lookes something like this.
shell.run('clear')
print("how many blocks should i go down?")
local x = io.read()
for i = 1, x do
CheckFuel()
Mine()
Stairs()
end
Yes i have functions setup for Mine() Stairs() CheckFuel() and Torch(). (didnt inclue because i wanted this post to stay short and simple.)
my question is how do i make it so every 5 loops it will send Torch()?
off topic but if you use shell.run("clear") to clear you could also use term.clear()
and I suggest using this it prevents a error when you would type a word
term.clear()
print("how many blocks should i go down?")
local x = io.read()
if type(x) == "number" then
for i = 1, x do
CheckFuel()
Mine()
Stairs()
end
else
term.setCursorPos(1,2)
print("please use a number")
end