What is the best way?
#1

Hello,

I came up here with a question. What would you prefer to use? See codes below:

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        
#define vehicle GetPlayerVehicleID(playerid)
        
if(vehicle == Player[playerid][pCar]) SendClientMessage(playerid"It's your vehicle");
        
// codes to be used with vehicle
    
}
    return 
1;

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        new 
vehicle GetPlayerVehicleID(playerid);
        if(
vehicle == Player[playerid][pCar]) SendClientMessage(playerid"It's your vehicle");
        
// codes to be used with vehicle
    
}
    return 
1;

So point of my question is to know what is the best way to use, #define or new? Please don't criticize if it's really a silly question.
Reply
#2

2nd one is best
Reply
#3

Quote:
Originally Posted by Hanuman
Посмотреть сообщение
2nd one is best
Why don't you explain to him why?


The first method is definately not the way to do things. In fact, you don't really need a variable at all, just do this if you only need it once:

pawn Код:
if(GetPlayerVehicleID(playerid) == Player[playerid][pCar]) SendClientMessage(playerid, "It's your vehicle");
@Vanchesta (OP): Please use [ pawn ] tags, not php.
Reply
#4

try to use 2nd codes
Reply
#5

Quote:
Originally Posted by Lloyde
Посмотреть сообщение
try to use 2nd codes
There have been two replies. One saying exactly this, and mine, which gave a reason why. Was your post really necessary?
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
There have been two replies. One saying exactly this, and mine, which gave a reason why. Was your post really necessary?
Yep it was necessary for increasing his post.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why don't you explain to him why?


The first method is definately not the way to do things. In fact, you don't really need a variable at all, just do this if you only need it once:

pawn Код:
if(GetPlayerVehicleID(playerid) == Player[playerid][pCar]) SendClientMessage(playerid, "It's your vehicle");
@Vanchesta (OP): Please use [ pawn ] tags, not php.
No mate, I ain't gonna use it once, there will be multiple actions with it, that's why I added "codes to be used with vehicle" as a comment. Well, I noticed that if you use #define anywhere at script then it affects to whole code, so I decided to undefine it when the function ends. So what's better now?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        #define vehicle GetPlayerVehicleID(playerid)
        if(vehicle == Player[playerid][pCar]) SendClientMessage(playerid, "It's your vehicle");
        // codes to be used with vehicle
        #undef vehicle
    }
    return 1;
}
or

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicle GetPlayerVehicleID(playerid)
        if(vehicle == Player[playerid][pCar]) SendClientMessage(playerid, "It's your vehicle");
        // codes to be used with vehicle
    }
    return 1;
}
P.S: Sorry if you don't understand me, I'm not best in speaking english at all.
Reply
#8

answer is same, just replace the line new vehicle GetPlayerVehicleID(playerid) with new vehicle = GetPlayerVehicleID(playerid);
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Anwarrex: That's not even CLOSE to correct! Don't compare features in PAWN to features in other languages like that - they are different languages for a reason. "#define" is a pure text replacement, go read my pre-processor tutorial for more information.
If #define is for replacement only, so my code looks same as GetPlayerVehicleID(playerid)? Am I right? If so, I'm gonna keep using defines instead of creating a variable.
Reply
#10

If you want to use the vehicleid for more than 2 times, storing the vehicleid in a variable is the best option instead of calling GetPlayerVehicleID over and over again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)