SA-MP Forums Archive
Weird string overwriting - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Weird string overwriting (/showthread.php?tid=454957)



Weird string overwriting - SimonItaly - 31.07.2013

I think images and code speak by themselves.


(It's a dialog showing a list of possibile options. "Lavori" means "Jobs" in Italian)

pawn Код:
if(response)
{
    print(inputtext);
    format(string, sizeof(string), "Guide/%s.info", inputtext);
    print(string);
    ...


I'm not getting it. Why does the point mess up this string formatting?


Respuesta: Weird string overwriting - JustBored - 31.07.2013

Quote:
Originally Posted by DarkSlyder
Посмотреть сообщение
I think images and code speak by themselves.


(It's a dialog showing a list of possibile options. "Lavori" means "Jobs" in Italian)

pawn Код:
if(response)
{
    print(inputtext);
    format(string, sizeof(string), "Guide/%s.info", inputtext);
    print(string);
    ...


I'm not getting it. Why does the point mess up this string formatting?
As i know, the listed dialogs doesnt return a text.


Re: Weird string overwriting - SimonItaly - 31.07.2013

No, they do. They return the text of the line you clicked. As you can see I've already tested that ("print(inputtext);").


Re: Weird string overwriting - dEcooR - 31.07.2013

dude i gues there is an string so use printf();


Re: Weird string overwriting - Scottas - 31.07.2013

sorry, misread

Can you show more code? Where you declared 'new string'?


Re: Weird string overwriting - SimonItaly - 31.07.2013

I don't need to print that string, I need to open a file with that name (scriptfiles/Guide/Lavori.info).
The string is declared at the first line of OnDialogResponse. I use it for every dialog, instead of declaring a new string for every "case". I've already checked that the string is empty before formatting it.
I've also tried to "create" the path string with "strcat" or by copying words one by one, but it didn't succeed.


Re: Weird string overwriting - Konstantinos - 31.07.2013

But does it actually format it correctly? Try like someone above said with printf just for a debug to see what it prints.
pawn Код:
printf("Guide/%s.info", inputtext);



Re: Weird string overwriting - SimonItaly - 31.07.2013

Just tested, same result.


Re: Weird string overwriting - Konstantinos - 31.07.2013

It's something wrong on your side. I tested it and it works fine.

PS: I just use an include for includes, but it still should work with the normal way.
pawn Код:
#define FILTERSCRIPT

#include < a_samp >
#include < easydialog >
#include < zcmd >

CMD:test( playerid, params[ ] )
{
    ShowDialog( playerid, Show:Test, DIALOG_STYLE_LIST, "Test", "Lavori\nNegozi di abbigliamento\nLuoghi comuni\nDistributori di benzina\nBar\nRistoranti\nCasino", "Select", "Cancel" );
    return 1;
}

Dialog:Test( playerid, response, listitem, inputtext[ ] )
{
    if( response )
    {
        print( inputtext );
        printf( "Guide/%s.info", inputtext );
    }
    return 1;
}
Quote:

[20:38:52] Lavori
[20:38:52] Guide/Lavori.info




Re: Weird string overwriting - SimonItaly - 31.07.2013

You're right, just tested on a blank gamemode and your code worked good.
It must be something related to the creation of the dialog.
pawn Код:
COMMAND:guidatest(playerid, params[])
{
    new File: file = fopen("Guide/Guide_Main.info", io_read),
        string[64], longstring[600];
    if(file)
    {
        while(fread(file, string))
        {
            strcat(longstring, string);
            strcat(longstring, "\n");
        }
        fclose(file);
        ShowPlayerDialog(playerid, 999, DIALOG_STYLE_LIST, "Guida", longstring, "Seleziona", "Annulla");
    }
    return 1;
}
I've tested this on the same filterscript and the commands (/test, /guidatest) printed two different results with the same dialog list.


Re: Weird string overwriting - SimonItaly - 01.08.2013

Bump.


Re: Weird string overwriting - park4bmx - 01.08.2013

is that string global ?

Also u can debug it by making a custom print function and fallowing where inputs are coming from