Question about Strings -
NeroX98 - 11.06.2015
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);
}
Re: Question about Strings -
Sawalha - 11.06.2015
yes, since it's a global variable
Re: Question about Strings -
Konstantinos - 11.06.2015
https://sampforum.blast.hk/showthread.php?tid=491035
Re: Question about Strings -
NeroX98 - 11.06.2015
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 ?
Re: Question about Strings -
Vince - 11.06.2015
It shouldn't because the server is single threaded but nevertheless, don't do it. It's just bad practice.
Re: Question about Strings -
Sawalha - 11.06.2015
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...
Re: Question about Strings -
NeroX98 - 11.06.2015
Okay guys, Thank you for your info
Luv ya
Re: Question about Strings -
Stanford - 11.06.2015
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///)