local function func(Health,Energy)
local a = {"Health","Energy"}
for i,v in pairs (a) do
print(v, to?(v) ) -- I want it to print Health,1 Energy,2 and not 1,1 2,2
end
end
func(1,2)
Yeah, it’s weird how I format the code, but it needs to be done like this.
local function func(Health,Energy)
local a = {"Health","Energy"}
for i,v in ipairs (a) do
print(v, i) -- I want it to print Health,1 Energy,2 and not 1,1 2,2
end
end
func(1,2)
Doing the loop in ipairs will be better choice. You can read something about it, my brain is too small to explain it
function func( values )
for i, v in pairs( values ) do
print( i, v )
end
end
func( {
Health = 10,
Energy = 8,
} )
Without any extra context on what the end goal is, it’s hard to recommend which is best for your case, or if another method not included is best. There’s many many ways to achieve this.