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

How to store variables in a table, to then be changed later?

Asked by 3 years ago
Edited 3 years ago

The title mostly sums up my issue. I need to run multiple repetitions of the same code, so im trying to use a "for i,v in pairs" loop to do so (i have used them before). However I know that I need to use a table of values to put through the loop. So I have the variables I need, I put them in a table and put them in the loop. However I need to be able to change the initial variables under certin conditions determined in for loop. Problem is, I can only change the values in the table, and not the original values. Let me know if that makes sense, or if any clarification is needed.

Ex)

local Var = 5
local Var2 = 6
local Var3 = 7
local BigestNum = 0

local Nums = {Var5, Var6, Var7}

for i,v in pairs(Nums)
    if i > BigestNum then
        i = BigestNum
    end
end

(My goal is to change one of the original variable, and not the values stored in the table) I hope that makes sense.

0
can you possibly show code example? thanks imKirda 4491 — 3y
0
As Kirda said, code example would be great, but I think I understand what you mean, and my reply is to use the variables in the table, don't use the ones outside of it Spjureeedd 385 — 3y

Answer this question