Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
set a boolean value to a default value if it is not set (nil) — Gideros Forum

set a boolean value to a default value if it is not set (nil)

MoKaLuxMoKaLux Member
edited June 2021 in General questions
a question for you please :)
Is it possible to set a boolean value to a default value if it is not set (nil)?

I am trying the ternary lua way but it does not work for me :/ https://wiki.gideros.rocks/index.php/Examples#TERNARY_OPERATOR_https:.2F.2Fwww.lua.org.2Fpil.2F3.3.html
-- tests
local thover = false -- test
local hover = thover and false or true -- I want to set boolean default = true
print("TEST", hover) -- it always prints TRUE :-/
I can achieve what I want using this but it is a hack :D
local thover = nil -- test
local hover2 = thover or 0
if hover2 == 0 then hover2 = false else hover2 = true end
print("TEST", hover2)
How do you handle this please?
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

Comments

  • hgy29hgy29 Maintainer
    Accepted Answer
    This should work to assume 'nil' should be seen as 'true'
    hover=thover or (thover==nil)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • thank you captain hgy29 that worked :) <3
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.