Question about dialogs
#1

Hey,
I am scripting furnitures system, and I would like to check what furniture did the player choose from a dialog. Since there are many furnitures, I am looking for a more effective way than doing like this:
pawn Код:
switch(listitem)
{

case 1:
{ }

case 2:
{ }
...
}
Is there any way to do it in another way than checking by case for each furniture? It's up to 15 options! I am looking for a more effective way.
Reply
#2

ShowPlayerDialog(playerid, DIALOG_EX, DIALOG_STYLE_LIST, "Choose items ","1st\n2nd\n3rd\n4th","Ok","Cancel");

Quote:

if(dialogid == DIALOG_EX)
{
if(!response) return SendClientMessage(playerid,0x0498FBC8,"Selection Cancled");
if(response)
{
new string[300];
new msg[200];
if(listitem == 0)
{
//1stitem
return 1;
}
if(listitem == 1)
{
//2nd
return 1;
}
if(listitem == 2)
{
//3rd
return 1;
}
if(listitem == 3)
{
//4th
return 1;
}
}

and etc
Reply
#3

Quote:
Originally Posted by HuntingMan
Посмотреть сообщение
ShowPlayerDialog(playerid, DIALOG_EX, DIALOG_STYLE_LIST, "Choose items ","1st\n2nd\n3rd\n4th","Ok","Cancel");

pawn Код:
if(dialogid == DIALOG_EX)
{
if(!response) return SendClientMessage(playerid,0x0498FBC8,"Selection Cancled");
if(response)
{
new string[300];
new msg[200];
if(listitem == 0)
{
//1stitem
return 1;
}
if(listitem == 1)
{
//2nd
return 1;
}
if(listitem == 2)
{
//3rd
return 1;
}
if(listitem == 3)
{
//4th
return 1;
}
}
and etc
Doing it this way is less efficient than using cases. If you're looking for a way to shorten up the list, it depends on how it's coded. For example, if several of the options will lead to the same result, you can bundle it up as one with cases.

pawn Код:
switch(listitem)
{
    //Let's say listitem 0-3 will lead to the same result
    case 0..3:
    {
        //Whatever code you place in here will work for the first 3 options.
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)