I have called functions in loops many times and I was wondering if it the right method?
I believe that this is a poor way of calling a function from a loop:
local function run(number) if (number == 1) then print("the number is " .. number) end while script.Parent.Disabled == false do local randomNum = math.random(1, 4) wait() run(randomNum) end
I have done this before but I am not sure if it is reliable enough to use in a popular published game:
functionRunning= false local function run(number) functionRunning = true if (number == 1) then print("the number is " .. number) functionRunning = false end while loopRunning == false do local randomNum = math.random(1, 4) wait() run(randomNum) end
Please let me know if there is any better way to call a function repeatedly from a loop. I have real code (not just examples) if that is needed to find the answer to this question please let me know and I could also post that here.
It all depends on your logic. Running a function inside of a loop is not a bad thing. As long as you keep in mind that the loop will not continue until the function ends.
Always double check to make sure your loops and logic are correct to prevent crashes or any other game breaking errors.
If you have any other questions, let me know.