Public function cannot have default values?
#1

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(playeridban falselogin false)
{
    
Kick(playerid);
    return 
1;

Code:
 error 059: function argument may not have a default value (variable "ban")
Reply
#2

Why are you creating this like
PHP Code:
 PUBLIC:kick(playeridban falselogin false
Create like this
PHP Code:
PUBLIC:kick(playerid)
{
Kick(playerid);
return 
1;

Reply
#3

Quote:
Originally Posted by Pearson
View Post
Why are you creating this like
PHP Code:
 PUBLIC:kick(playeridban falselogin false
Create like this
PHP Code:
PUBLIC:kick(playerid)
{
Kick(playerid);
return 
1;

Because I need to put arguments.. It's the purpose.. '-'
Reply
#4

ban don't have default argument. you need to create it yourself .
Reply
#5

Quote:
Originally Posted by Pearson
View Post
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"
Reply
#6

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
Reply
#7

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(delayplayeridban falselogin false)
{
    return 
SetTimerEx("public_kick"delay0"iii"playeridbanlogin);

note the return, so now you can do mytimervariable=call_kick(1000, playerid); and kill the kick timer from mytimervariable.
Reply
#8

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
Reply
#9

Quote:
Originally Posted by OneDay
View Post
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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)