Global vs local string
#1

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)