Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to toggle a while loop/ reuse a return function?

Asked by 5 years ago
Edited 5 years ago

Please note my scripting abilities are still limited.

The code I have posted below places a table into a fake array and randomly displays a table key and its value, it will continuously search through the entire array until a desired number is found.

Upon finding a desired number the script intentionally breaks its loop cycle.

Unfortunately, I would like to be able to reuse this function at all times and trigger it when necessary.

I suspect that the code needs some rewritting and you can't simply use an if statement trigger because of the while loop breaking. What would my best approach be?

01Player1Grid = {
02    ["A1"] = 1,
03    ["A2"] = 2,
04    ["A3"] = 3,
05    ["A4"] = 4,
06    ["A5"] = 5,
07    ["A6"] = 6,
08    ["A7"] = 7,
09    ["A8"] = 8,
10    ["A9"] = 9,
11    ["A10"] = 10
12}
13 
14while wait() do -- Perform loop and wait function to prevent fatal lag.
15    local function GenerateRandomIndex()
View all 34 lines...

1 answer

Log in to vote
0
Answered by 5 years ago
01function place()--Makes it a function
02    Player1Grid = {
03    ["A1"] = 1,
04    ["A2"] = 2,
05    ["A3"] = 3,
06    ["A4"] = 4,
07    ["A5"] = 5,
08    ["A6"] = 6,
09    ["A7"] = 7,
10    ["A8"] = 8,
11    ["A9"] = 9,
12    ["A10"] = 10
13}
14 
15while wait() do -- Perform loop and wait function to prevent fatal lag.
View all 38 lines...

You can call the place function as often as you want now.

I hope this helped and hope you will be a great scripter, one day!

0
OOF, guess I was just focusing on the wrong thing. Thanks Sonnenroboter! BlackeyeI 19 — 5y
Ad

Answer this question