Skyliquid
Skyliquid

Reputation: 392

Lua how to assign default array value to '0' not nil

I was getting lately an error in Lua saying cannot assign arithmetic value of '?'. then I realized that I need to define how many storage are in my array and assigning them to a value,

this gave me Error : locator = {}

this Worked fine : locator = {0,0,0,0,0,0,0,0,0,0}

So now I have another array that I need a loop to store 200 values in it, so how to define the storage and values within it without something like this : a = {0,0,0,0,0,...... etc}

Any Ideas ?

Upvotes: 1

Views: 1060

Answers (1)

Skyliquid
Skyliquid

Reputation: 392

this is what worked for me :

locator = {}

for i = 1, 200 do 
locator[i] = 0 
end

just assigning all to 0 inside a loop Before using them

Credits : Egor Skriptunoff

Upvotes: 3

Related Questions