Answered Help with functions

Aspire

Known Member
Messages
31
Reaction score
14
Points
118
I've seen functions like this and don't really know what they mean:
Code:
function test(bool = true)
{
    if(bool == true)
    {
        self iPrintLn("True");
    }
    else
    {
        self iPrintLn("False");
    }
}
 

Cxwh

Veteran
Messages
64
Reaction score
45
Points
793
I think it would be the same as
Code:
function test(bool)
{
    if(!isDefined(bool))
        bool = true;

    if(bool)
        self iPrintLn("True");
    else
        self iPrint("False");
}
So
Code:
function test(bool = true) //makes bool true if bool is undefined
 
P

Patrick

Guest
I've seen functions like this and don't really know what they mean:
Code:
function test(bool = true)
{
    if(bool == true)
    {
        self iPrintLn("True");
    }
    else
    {
        self iPrintLn("False");
    }
}
That should give you a syntax error but its basically just going to return a iprintLn depending if the variable is true or false.
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,093
Reaction score
2,881
Points
1,103
I think it would be the same as
Code:
function test(bool)
{
    if(!isDefined(bool))
        bool = true;

    if(bool)
        self iPrintLn("True");
    else
        self iPrint("False");
}
So
Code:
function test(bool = true) //makes bool true if bool is undefined
@Aspire This exactly describe what it does :peace: :smile: Good job @Cxwh!

Question answered.
 
Top