OnPlayerKeyStateChange returning - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerKeyStateChange returning (
/showthread.php?tid=560837)
OnPlayerKeyStateChange returning -
rOps - 30.01.2015
Hi all, I don't understand when I should write 'return 0;' or 'return 1;' when I want to call OnPlayerKeyStateChange, as example:
Код HTML:
if(playerhavesomething)
{
if(isplayerinrangeofpoint)
{
if(playerhavesomething2)
{
//
}
}
}
So when i should write return and WHY? Or maybe I shouldn't write this?
And sorry for my bad english.
Re: OnPlayerKeyStateChange returning -
Abagail - 30.01.2015
When you want to return the statement, typicall when your code ends.
For example,
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE))
{
if(player_idle_status == true)
{
player_idle_status[playerid] = false;
return 1;
}
return 1;
}
return 1;
}
As you can see, we typically return a value when needed, and or when our code is over.
Re: OnPlayerKeyStateChange returning -
CalvinC - 30.01.2015
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(playerhavesomething)
{
if(isplayerinrangeofpoint)
{
if(playerhavesomething2)
{
//
}
}
}
return 1;
}
You return 1 at the end, since it executed right. You almost always return 1 at the end of functions, which stops the code and lets the server know it worked correctly.
Re: OnPlayerKeyStateChange returning -
rOps - 30.01.2015
But if I have a lot functions with one key?
Re: OnPlayerKeyStateChange returning -
Abagail - 30.01.2015
Then you should put them after each code segment, along with after everything.