What faster or better?
#7

I'd just like to add a few comments to this thread, because a few people have missed this out:

PVars are convenient - yes, but the lookup speed is also slower.

I'd suggest using normal arrays/enums for player variables, however you should use PVars for variables that aren't always going to be in use, say that you put a player in a DM arena, you want to track where they are, but not all players are going to be there, you should use PVars, here's a quick example of what I mean:

pawn Код:
stock PutPlayerInArena(playerid) {
    // This function was created for the purpose of this thread.
    SetPlayerPos(playerid, 0, 0, 0);
    SetPlayerInterior(playerid, 0);
    SetPVarInt(playerid, "Arena", 1);
    return 1;
}

CMD:sawnoff(playerid, params[]) {
    if(GetPVarInt(playerid, "Arena") != 0) // We're tracking if the player is in the arena. If a PVar doesn't exist, it'll return 0.
        return SendClientMessage(playerid, 0, "You can't do this while you're in the arena!");
       
    // Giving the player a sawn-off shotgun with 500 ammo (example from wiki)
    GivePlayerWeapon(playerid, 26, 500);
    return 1;
}
Basically, what I mean is - not everyone will be in the arena, so using is a lot more convenient - but you're also saving memory, because that variable won't always be in use so it won't always be declared, unlike arrays/normal variables.
Reply


Messages In This Thread
What faster or better? - by Nexotronix - 02.04.2011, 20:07
Re: What faster or better? - by admantis - 02.04.2011, 20:07
Re: What faster or better? - by aircombat - 02.04.2011, 20:09
Re: What faster or better? - by DRIFT_HUNTER - 02.04.2011, 20:19
Re: What faster or better? - by PowerPC603 - 02.04.2011, 21:48
Re: What faster or better? - by Nexotronix - 16.04.2011, 13:19
Re: What faster or better? - by Calgon - 16.04.2011, 14:17
Re: What faster or better? - by Scenario - 16.04.2011, 14:22

Forum Jump:


Users browsing this thread: 2 Guest(s)