Global vs local string - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Global vs local string (
/showthread.php?tid=86289)
Global vs local string -
ledzep - 13.07.2009
I was just wondering if using a global string like this:
pawn Код:
new string[128];
...
dcmd_mycommand(playerid, params[])
{
format(string, sizeof(string), "Your player ID is %d.", playerid);
SendClientMessage(playerid, myColour, string);
return 1;
}
...
public OnPlayerSpawn(playerid)
{
format(string, sizeof(string), "You have spawned, and your player ID is %d.", playerid);
SendClientMessage(playerid, myColour, string);
}
vs making new local strings every time you need one:
pawn Код:
dcmd_mycommand(playerid, params[])
{
new string[128];
format(string, sizeof(string), "Your player ID is %d.", playerid);
SendClientMessage(playerid, myColour, string);
return 1;
}
...
public OnPlayerSpawn(playerid)
{
new string[128];
format(string, sizeof(string), "You have spawned, and your player ID is %d.", playerid);
SendClientMessage(playerid, myColour, string);
}
Would possibly cause problems?
The reason I ask is because these strings will constantly be getting formatted by different parts of the script.
Re: Global vs local string -
Weirdosport - 13.07.2009
It won't cause problems, using global strings is better practice if you do not value the contents of them once they've been used.
Re: Global vs local string -
TuNeFisH - 13.07.2009
And i think reserving a place in the memory for a variable each time you need it would take some microseconds more than reserving it ONCE initially and just using it each time you need it. :P