Public function cannot have default values? -
Dayrion - 09.11.2016
Hello. That's the question.
Public functions (all of them are for timers) cannot have default values? If no, I need to create multiple functions?
PHP Code:
PUBLIC:kick(playerid, ban = false, login = false)
{
Kick(playerid);
return 1;
}
Code:
error 059: function argument may not have a default value (variable "ban")
Re: Public function cannot have default values? -
Pearson - 09.11.2016
Why are you creating this like
PHP Code:
PUBLIC:kick(playerid, ban = false, login = false)
Create like this
PHP Code:
PUBLIC:kick(playerid)
{
Kick(playerid);
return 1;
}
Re: Public function cannot have default values? -
Dayrion - 09.11.2016
Quote:
Originally Posted by Pearson
Why are you creating this like
PHP Code:
PUBLIC:kick(playerid, ban = false, login = false)
Create like this
PHP Code:
PUBLIC:kick(playerid)
{
Kick(playerid);
return 1;
}
|
Because I need to put arguments.. It's the purpose.. '-'
Re: Public function cannot have default values? -
Pearson - 09.11.2016
ban don't have default argument. you need to create it yourself .
Re: Public function cannot have default values? -
Sew_Sumi - 09.11.2016
Quote:
Originally Posted by Pearson
ban don't have default argument. you need to create it yourself .
|
He's trying, that's where he's at currently.
Apparently you can't use Public functions to do this. That is from a ****** search of "pawn error 059"
Re: Public function cannot have default values? -
OneDay - 10.11.2016
you can put this in another function like
Code:
forward public_kick(playerid, ban, login);
public public_kick(playerid, ban, login)
{
Kick(playerid);
return 1;
}
stock call_kick(delay, playerid, ban = false, login = false)
{
SetTimerEx("public_kick", delay, 0, "iii", playerid, ban, login);
}
then just use call_kick to kick or you could use a define
Re: Public function cannot have default values? -
PrO.GameR - 10.11.2016
As you are saying all of them are for timers you can use a defined function to use the defaults and use the actual syntax when giving it your own variable values.
or just use a stock like the guy above me, just with small changes.
PHP Code:
#define DefaultKick(%0, %1) SetTimerEx("public_kick", %0, 0, "iii", %1, false, false);
or
stock call_kick(delay, playerid, ban = false, login = false)
{
return SetTimerEx("public_kick", delay, 0, "iii", playerid, ban, login);
}
note the return, so now you can do mytimervariable=call_kick(1000, playerid); and kill the kick timer from mytimervariable.
Re: Public function cannot have default values? -
OneDay - 10.11.2016
that define is not working and also has a semicolon
Code:
too many parameters
DefaultKick(playerid, true);
bad syntax
DefaultKick(playerid, .login=true);
if the defaults are not the same
#define DefaultKick(%0, %1) SetTimerEx("public_kick", %0, 0, "iii", %1, false, true);
DefaultKick(playerid, true);
has login to false in a hidden way not the default
Re: Public function cannot have default values? -
Dayrion - 10.11.2016
Quote:
Originally Posted by OneDay
you can put this in another function like
Code:
forward public_kick(playerid, ban, login);
public public_kick(playerid, ban, login)
{
Kick(playerid);
return 1;
}
stock call_kick(delay, playerid, ban = false, login = false)
{
SetTimerEx("public_kick", delay, 0, "iii", playerid, ban, login);
}
then just use call_kick to kick or you could use a define
|
Pretty smart, thanks.