[Ajuda] Sobre otimizaзгo
#9

Quote:
Originally Posted by zSuYaNw
View Post
Mas se vocк usar assim, irб dar problema..


Imaginamos que vocк use a string em uma callback ou funзгo assim:
pawn Code:
GetPlayerName(playerid, string, 24); // armazenamos o nome do jogador na string
printf("Nome do jogador й: %s", string);
Saida: Nome do jogador й: zSuYaNW

Aн, vocк irб usar novamente a array string em OUTRA callback/funзгo:
pawn Code:
GetPlayerIp(playerid, string, 16);
printf("Ip do jogador й %s", string);
Saida: Nome do jogador й: zSuYaNWIp do jogador й 192.168.0.1

Este fenфmeno acontece porque vocк utilizou a string e nгo limpou ela apуs a utilizaзгo.
zSuYaNw, a limpeza em strings globais (ou estбticas locais) deve ser feita antes do uso de funзхes que modificam as mesmas, como strmid e strcat (especialmente strcat).

Eu entendi seu exemplo, mas houve um equнvoco da sua parte ao escolher GetPlayerName e GetPlayerIp, visto que essas funзхes jб fazem a limpeza da string antes de passar o retorno. Veja:

PHP Code:
new gString[128];
public 
OnGameModeInit()
{
    
gString "String inicial";
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    print(
gString);
    
GetPlayerName(playeridgString24);
    
printf("Nome: %s"gString);
    
GetPlayerIp(playeridgString16);
    
printf("IP: %s"gString);
    return 
1;

Saнda:
Quote:

String inicial
Nome: zPain
IP: 127.0.0.1

Reply


Messages In This Thread
Sobre otimizaзгo - by pWesley - 06.06.2016, 05:21
Re: Sobre otimizaзгo - by Ermanhaut - 06.06.2016, 05:24
Re: Sobre otimizaзгo - by F1N4L - 06.06.2016, 11:16
Re: Sobre otimizaзгo - by ZEDD666 - 06.06.2016, 12:20
Re: Sobre otimizaзгo - by zSuYaNw - 06.06.2016, 14:03
Respuesta: Sobre otimizaзгo - by OverKiller - 06.06.2016, 15:07
Re: Sobre otimizaзгo - by pWesley - 06.06.2016, 15:59
Re: Sobre otimizaзгo - by zSuYaNw - 06.06.2016, 16:13
Re: Sobre otimizaзгo - by zPain - 06.06.2016, 17:12
Re: Sobre otimizaзгo - by zSuYaNw - 06.06.2016, 17:14
Re: Sobre otimizaзгo - by pWesley - 06.06.2016, 18:16
Re: Sobre otimizaзгo - by zSuYaNw - 06.06.2016, 18:21
Re: Sobre otimizaзгo - by pWesley - 06.06.2016, 19:01

Forum Jump:


Users browsing this thread: 1 Guest(s)