Search
 
SCRIPT & CODE EXAMPLE
 

LUA

lua how to default value if nil or false

local function foo(x, y, z)
    local x = x or true
    local y = y or 1234
    z = z or "default"
end
Comment

lua how to default value if nil

function foo(x, y, z)
    x = (x == nil) or x
    y = (y == nil and 1234) or y
    z = (z == nil and "default") or z
    print(x, y, z)
end

> foo()
true    1234    default
> foo(false, false, "me")
false   false   me
> foo(nil, 50, "me")
true    50  me
Comment

PREVIOUS NEXT
Code Example
Lua :: table.move lua 
Lua :: lua add to table 
Lua :: How to create a part with script in roblox srudio 
Lua :: name is not a valid member of Folder roblox 
Lua :: how to activate a command if someone wears a accessory in lua roblox 
Matlab :: save mat file script in matlab directory 
Matlab :: anonymous function matlab 
Matlab :: dat file in matlab 
Matlab :: matlab random 
Matlab :: matlab variables 
Matlab :: octave a:b:c range 
Basic :: how to add basic authentication on haproxy backend server 
Basic :: how to round a number in visual basic 
Basic :: wussup 
Elixir :: elixir try rescue 
Elixir :: elixir map to new map 
Elixir :: liveview component 
Scala :: array in scala 
Scala :: scala yield how to share one loop 
Actionscript :: rabbitmq docker cant connect localhost 
Excel :: google sheets sort column by item frequency 
Perl :: perl print an array 
Perl :: len perl 
Pascal :: for loop pascal 
Powershell :: powershell show which diorecty is temp 
Clojure :: folding at home linuxserver.io 
Assembly :: x86 assembly hello world 
Assembly :: how to listen for changes on an ObservableMap 
Javascript :: jquery vslidation remove spaces from input 
Javascript :: jquery unselect option 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =