![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Y_VRN |
I came from using Lua, and in the language, I can do something like this:
local X = nil
local Y = "Yes" -- "fallback"
local Z = X or Y -- This
If X is nil/null, then check if Y should be used. I can even make it a long chain too:
local X, Y, Z, A, B, C = nil, nil, nil, 2, "String", true
local Final = X or Y or Z or A or B or C
print(Final) -- should print the value of A, since it is the first variable in the chain to have a value.
Currently, I’m stuck in GDScript trying to achieve something similar to Lua. What I have in mind only is to use if-statements, but that would be too messy for me. Is there a way to do something similar to Lua? As in…
func Function(Name):
var N = Name or "Default"
print(N)
GDScript always outputs a boolean (mostly “True”) instead of the value I want.
Thanks in advance.