How to default a value?

In this piece of code, I want to add a default value. But don’t want to bother with a long statement.
How am I suppose to accomplish this?

function Some (inv)
    asd = inv or true 


It doesn’t give me false in the output.

can you tell us more? I don’t really understand your issue with that

1 Like

What I want to do is I want to make the default value of “asd to true” if the inv doesn’t include any value so if The function doesn’t has any value I’ll make the asd = true but if it has any bool value then i’ll convert the asd to that value without making the code in multiple lines.

so if the value in the function (inv) is empty(?) or doesnt equal to a certain value then set the asd to true, and if it has then set asd to the “inv” value? I understood correctly?

1 Like

exactly, accurate! and remember I am passing only booleans not int nor strings

If you want to have a default parameter value, and assuming that “no value” means nil, you could do the following:

local function func(param)
    param = param == nil and true or param

func() --> true
func(false) --> false
func(100) --> 100 
1 Like

Yep this is the one I was looking for… kinda tricky to remember but hopefully i’ll get used to it. <3