Question about Strings
#1

Hello,
I have a question about strings. Can i use one universal string for all purposes?
For example:
pawn Код:
new UniversalString[126];

public OnplayerConnect
{
   //Other Code
   format (UniversalString, sizeof(UniversalString), "{3D53F5}(Server Info) {FFFFFF}%s has joined the server!", name);
   SendClientMessage(playerid, ServerInfo, UniversalString);
}

public OnplayerDisconnect
{
   //Other Code
   format (UniversalString, sizeof(UniversalString), "{3D53F5}(Server Info) {FFFFFF}%s has left the server!", name);
   SendClientMessage(playerid, ServerInfo, UniversalString);
}
So as you can see there, I format the same string i declared on the start of the gamemode.

Is is better to make the strings this way or to declare new strings when i need like this?
pawn Код:
public OnplayerConnect
{
   //Other Code
   new LocalString[128];
   format (LocalString, sizeof(LocalString), "{3D53F5}(Server Info) {FFFFFF}%s has joined the server!", name);
   SendClientMessage(playerid, ServerInfo, LocalString);
}

public OnplayerDisconnect
{
   //Other Code
   new LocalString[128];
   format (LocalString, sizeof(LocalString), "{3D53F5}(Server Info) {FFFFFF}%s has left the server!", name);
   SendClientMessage(playerid, ServerInfo, LocalString);
}
Reply
#2

yes, since it's a global variable
Reply
#3

https://sampforum.blast.hk/showthread.php?tid=491035
Reply
#4

Quote:
Originally Posted by Sawalha
Посмотреть сообщение
yes, since it's a global variable
Yeah but i'm afraid if there are about 50 players on the server and at the same time one player disconnects and one connects, so what will happen ? It will mix the strings ?
Reply
#5

It shouldn't because the server is single threaded but nevertheless, don't do it. It's just bad practice.
Reply
#6

well yea as the guy above me mentioned, i just noticed that data are going to be overwritten if the string going to be formatted in the same moment (player connects and one disconnects in the same time), however, that rarely happens, but still it can happen so.. you have to use a single string for each command / function / callback...
you can see what ****** said in that topic that Konstantinos given you it's link..
i apologize for giving you incorrect info, i never thought that data would be overwritten...
Reply
#7

Okay guys, Thank you for your info
Luv ya
Reply
#8

Can anyone explain why this is basically a bad practice if it's possible? Thanks!

Just wondering since Vince said that the server is single threaded.. On other hand, I don't know if keeping definging a large query string is better or not (for example 2048///)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)