Mess up after update of my code
#1

Hello, so I've been working on my code so it looks and runs better, but before the update, I had strings everywhere, like 10 difference strings, I was told it would use a lot of space, so I changed all the strings I had into "ustr" for the normal string then "strd" for dialog formating as well as "lstr" for logging command uses, so since I update this I've been having problems with my dialogs, they put messages into the dialog rather then the dialog it's self.
This is my code:
pawn Код:
CMD:stats(playerid, params[])
{
    format(strd, sizeof(strd), "{10F441}Gaming Time:{FFFFFF} %d:%d", pInfo[playerid][Hour], pInfo[playerid][Minute]);
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}Money:{FFFFFF} %d\n", GetPlayerMoney(playerid));
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}Kills:{FFFFFF} %d\n", pInfo[playerid][Kills]);
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}Deaths:{FFFFFF} %d\n", pInfo[playerid][Deaths]);
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}GP:{FFFFFF} %d\n", pInfo[playerid][GP]);
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}XP:{FFFFFF} %d\n", pInfo[playerid][XP]);
    strcat(ustr, strd);
    format(strd, sizeof(strd), "{10F441}Level:{FFFFFF} %d\n", pInfo[playerid][Level]);
    strcat(ustr, strd);
    SPD(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{33CCFF}Stats", ustr , "Close","");
    getdate(lyear, lmonth, lday);
    gettime(lhour, lminute, lsecond);
    GetPlayerName(ID, pName, sizeof(pName));
    format(lstr, sizeof lstr, "[COMMAND][%02d/%02d/%04d %02d:%02d:%02d]: %s(%d): has used /stats", lyear, lmonth, lday, lhour, lminute, lsecond, pName, ID);
    AllLogs(lstr);
    return 1;
}
But this is what I am getting when I use the command /stats

as you can see it's showing the in the stats command that I have leveled up, I chat it says the same thing...
Код:
        format(ustr, sizeof(ustr),"You have leveled up too level %d!",pInfo[playerid][Level]);
    	SCM(playerid, pink, ustr);
heres the line of that message.

pawn Код:
new ustr[128];//string
new strd [700];//dialog string
new lstr[400]; // Logging string
If you know anyway to help me that would be great, or if you see I have made a mistake somewhere could you point it out so I can learn and so it doesn't happen in future. Thank you
Reply
#2

ustr is way too small and strd too big

strd could be around 43
and ustr probably something close to 380
lstr could also be around 85 isntead of 400

just estimate the maximum size for each string, that'll help in the future too.
for example, something like this
pawn Код:
format(str,sizeof str,"hello %s!",name);
here it's

"hello " -> 6 chars
"%s" which equals to 24(max-name) -> 24 chars
"!" 1 char
'\0' 1cahr

so the optimal size of str would be 32
not too much adn not too less, just right.
Reply
#3

Ustr is used mainly on messages, so it has to be around 128 and lstr is used for the logging which has time day name and command in...
Reply
#4

Create the string in the command, not globally.

After the first string you forgot to use \n

Also you don't need the first strcat.
Reply
#5

Quote:

Create the string in the command, not globally.

That worked, thank you!
Reply
#6

To:
Situation A:
I am going to the cinema
Situation B:
I ranked up from corporal to sergeant!
Your situation:
You have leveled up to level 1!

Too:
Situation A:
Person 1: Dude, I ranked up from corporal to sergeant!
Person 2: Nice, me too!
Situation B:
Officer: You are driving too fast!
Reply
#7

What?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)