Hard_Code
(CarlHardCoded)
#1
is there any simple way to make this work without tables
function GetValue()
return 1,2
end
local a,b = 1 > 0 and GetValue()
print(a,b)
--1, nil
local c,d = GetValue()
print(c,d)
--1, 2
i know you can do a,b = 1 > 0 and 1,2 but can i return multiple with a single call
heII_ish
(heII_ish)
#2
I don’t think ternary assignment works like that with tuples
The simplest way would be to just use an if
statement
local a,b
if 1 > 0 then a,b = GetValue() end
Also,
This doesn’t work the way you think it does. a
is evaluated for everything before the comma, and then b
is just assigned the value of 2
It’s the same as doing
a = 1 > 0 and 1
b = 2
1 Like