23.11.2015, 17:22
Hello there !
I was testing a code in the callback OnPlayerKeyStateChange (NOTE: i have read the wiki page about that callback) and my code was working well but i have checked a thread/post were the code i was using was wrote in other way,check this -
Alright - That is my normal code that i have made thanks to the wiki information but i have noticed there was other way (in some random thread in the forum)- check below
Both codes/way do the same but i want to know why the second way is not in the wiki if it does the same function and i want to understand that code because as far i know "-" is not an operator ( oldkeys - newkeys == KEY_SPRINT)
Maybe some of you will say "don't worry about it if it's working" but i do want to know.
I was testing a code in the callback OnPlayerKeyStateChange (NOTE: i have read the wiki page about that callback) and my code was working well but i have checked a thread/post were the code i was using was wrote in other way,check this -
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((oldkeys & KEY_SPRINT) && !(newkeys & KEY_SPRINT))
{
// My Code
}
if ((newkeys & KEY_SPRINT) && !(oldkeys & KEY_SPRINT))
{
// My Code
}
return true;
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(oldkeys - newkeys == KEY_SPRINT)
{
// My code
}
if(newkeys - oldkeys == KEY_SPRINT)
{
// My code
}
return true;
}
Maybe some of you will say "don't worry about it if it's working" but i do want to know.