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

Im trying to insert the opposite of the value in a new table and its not working?

Asked by
yurhomi10 192
10 years ago

Im trying to print the opposite of a, b, a, a but its not working, help

a = true
b = false
new={ }
bool = { a, b, a, a}

print(table.unpack(bool, 1, #bool))
for k, v in pairs(bool) do
   for i = 1, #bool do
      table.insert(new, not v)
   end
end

print(table.unpack(new, #new))

Output : true false true true False

Edit(forgot to add iteration, changes to false once but wont insert the others.

1 answer

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

You don't need another for = i.. statement in your loop as the for k,v in pairs(bool) basically already does that, so it just needs to be like this. Also you don't use table.unpack, just unpack when using print.

a = true
b = false

new = { }
bool = {a, b, a, a}

print(unpack(bool, 1, #bool)) -- Returns: true false true true

local new = {}
for _,v in pairs(bool) do
table.insert(new,not v)
end

print(unpack(new, 1, #new)) -- Returns: false true false false
0
Thanks! yurhomi10 192 — 10y
Ad

Answer this question