OnPlayerKeyStateChange returning
#1

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

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

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

But if I have a lot functions with one key?
Reply
#5

Then you should put them after each code segment, along with after everything.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)