SA-MP Forums Archive
3D array into a dialog message - 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: 3D array into a dialog message (/showthread.php?tid=664244)



3D array into a dialog message - cataplasia - 22.02.2019

Hello,

I'm trying to insert a three-dimensional array into a dialog box. The code I have just outputs the standard error message whenever I try to type the command in-game. Not getting any compiler errors.

pawn Code:
CMD:teams(playerid, params[])
{
    new arenas[12][2][128] =
    {
        {"Dust 2", "Teaming permitted"},
        {"Jefferson Motel", "Teaming permitted"},
        {"Liberty City", "Teaming forbidden"},
        {"LVPD", "Teaming forbidden"},
        {"Madd Dogg's Mansion", "Teaming permitted"},
        {"Meat Factory", "Teaming forbidden"},
        {"Pleasure Domes", "Teaming forbidden"},
        {"RC Battle Ground", "Teaming permitted"},
        {"Tennis Court", "Teaming forbidden"},
        {"The Farm", "Teaming forbidden"},
        {"The Sewers", "Teaming permitted"},
        {"Western Town", "Teaming permitted"}
    };

    new string[512];

    for (new i=0; i < sizeof(arenas); i++)
    {
        for (new j=0; j < sizeof(arenas); j++)
        {  
            strcat(string, sprintf("%s\t%s\n", arenas[i][j], arenas[i][j], sizeof(string)));
        }
    }

    Dialog_Show(playerid, ArenasList, DIALOG_STYLE_MSGBOX, "Arena Teaming Rules", string, "OK", "OK");
    return 1;
}
I'm new, and I understand that you're probably cringing reading my code right now. I really appreciate your help regardless. Cheers!

Just to clarify, I want the array to be inserted into the dialog box so it outputs the contents of the array into the box.


Re: 3D array into a dialog message - CherryMond - 23.02.2019

In this case you don't need a second loop, it's enough:
PHP Code:
for (new 0sizeof(arenas); i++){
    
format(stringsizeof string"%s%s\t%s\n"stringarenas[i][0], arenas[i][1]);




Re: 3D array into a dialog message - Nero_3D - 23.02.2019

do you use that array somewhere else?, in your example you could put the text (with the correct formation) directly into Dialog_Show