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

Help With Targs In A Loop

Started by adencraft2000, 22 August 2013 - 01:42 AM
adencraft2000 #1
Posted 22 August 2013 - 03:42 AM
Hi, I have this program, http://pastebin.com/xwS2x1ab and I have this kind of loop

for i=1,5 do
--something
end
This loops 5 times.

I want it to accept an argument (for example "programName 10" will loop it 10 times

Thanks in advance,
Aden :)/>
Zudo #2
Posted 22 August 2013 - 03:48 AM

local sTimes = ...
local timesToRepeat = tonumber(sTimes)

if timesToRepeat == nil then
 print("That isn't a number")
 error()
end

for i = 1, timesToRepeat do
-- Do something
end

Untested, written in browser.

BTW, it doesn't need to be called tArgs, it is just "t" for table, then "Args" for arguments. It's used by the CC devs.
adencraft2000 #3
Posted 22 August 2013 - 05:32 AM
Thanks, Check out my pastebin for all my codes I wrote (Talked to someone who is very good at lua expecting to be told they are bad but was told they are quite good)
pastebin.com/u/ADENCRAFT20000

I recommend you install my scripts via my installer by running

pastebin get 68JHikjS installer
then running

installer