Which way is better?
#1

Hi guys, I wanna create a dialog and let the player input the color id (color1 and color2 of the vehicle) and I have two ways (one is define just 1 dialog and use PVar, two is define two dialog and not use PVar) to do this but I just don't know which way should I follow:

1:
PHP код:
#define DIALOG_MENUCOLOR 1
public OnPlayerClickPlayerTextDraw(playeridPlayerText:playertextid)
{
                else if(
playertextid == dealership_ColorMenu[3]) // color1
        
{
                        
SetPVarInt(playerid"ChoseColorID"1); 
            
ShowPlayerDialog(playeridDIALOG_COLORMENUDIALOG_STYLE_INPUT" ""Input the color1 id""Confirm""Cancel");
        }
        else if(
playertextid == dealership_ColorMenu[4]) // color2
        
{
                        
SetPVarInt(playerid"ChoseColorID"2);
            
ShowPlayerDialog(playeridDIALOG_COLORMENUDIALOG_STYLE_INPUT" ""Input the color1 id""Confirm""Cancel");
        }
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU:
        {
            if(
GetPVarInt(playerid"ChoseColorID") == 1// update the color 1 box textdraw if chose colorid is 1
            
{
                
PlayerTextDrawColor(playeriddealership_ColorMenu[3], vehicleColoursTableRGBA[strval(inputtext)]);
                
PlayerTextDrawShow(playeriddealership_ColorMenu[3]);
            }
            else if(
GetPVarInt(playerid"ChoseColorID") == 2// update the color 2 box textdraw if chose colorid is 2
            
{
                
PlayerTextDrawColor(playeriddealership_ColorMenu[4], vehicleColoursTableRGBA[strval(inputtext)]);
                
PlayerTextDrawShow(playeriddealership_ColorMenu[4]);
            }
        }
    }

2.
PHP код:
#define DIALOG_COLORMENU1 1
#define DIALOG_COLORMENU2 2
public OnPlayerClickPlayerTextDraw(playeridPlayerText:playertextid)
{
    if(
_:playertextid != INVALID_TEXT_DRAW)
    {
        else if(
playertextid == dealership_ColorMenu[3]) // color1
        
{
            
ShowPlayerDialog(playeridDIALOG_COLORMENU1DIALOG_STYLE_INPUT" ""Input the color1 id""Confirm""Cancel");
        }
        else if(
playertextid == dealership_ColorMenu[4]) // color2
        
{
            
ShowPlayerDialog(playeridDIALOG_COLORMENU2DIALOG_STYLE_INPUT" ""Input the color2 id""Confirm""Cancel");
        }
    }
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU1:
        {
            
PlayerTextDrawColor(playeriddealership_ColorMenu[3], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[3]);
        }
        case 
DIALOG_COLORMENU2:
        {
            
PlayerTextDrawColor(playeriddealership_ColorMenu[4], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[4]);
        }
    }

Thanks in advanced!
Reply
#2

I think 1? But with that modification:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU:
        {
            if(
GetPVarInt(playerid"ChoseColorID") == 1// update the color 1 box textdraw if chose colorid is 1
            
{
                
PlayerTextDrawColor(playeriddealership_ColorMenu[3], vehicleColoursTableRGBA[strval(inputtext)]);
                
PlayerTextDrawShow(playeriddealership_ColorMenu[3]);
                return 
1;
            }
            
PlayerTextDrawColor(playeriddealership_ColorMenu[4], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[4]);
            return 
1;
            }
        }
    }

This takes out a function call and a "else".
Reply
#3

Quote:
Originally Posted by 10MIN
Посмотреть сообщение
I think 1? But with that modification:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU:
        {
            if(
GetPVarInt(playerid"ChoseColorID") == 1// update the color 1 box textdraw if chose colorid is 1
            
{
                
PlayerTextDrawColor(playeriddealership_ColorMenu[3], vehicleColoursTableRGBA[strval(inputtext)]);
                
PlayerTextDrawShow(playeriddealership_ColorMenu[3]);
                return 
1;
            }
            
PlayerTextDrawColor(playeriddealership_ColorMenu[4], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[4]);
            return 
1;
            }
        }
    }

This takes out a function call and a "else".
I have read a thread that says using "if-else" is faster than just using if and return 1 and if again.
So according to that thread, I think my first one is faster, correct me if I'm wrong.
By the way, thank you!
Reply
#4

As far as I know if-else is slower or even equally, but not faster. Also pvars are used in gamemode <-> filterscript transition of variables. It could simply be a array.
You could even use the code with ternary operator like this:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU:
        {
            new 
colorid  = (GetPVarInt(playerid"ChoseColorID" == 1)) ? 4;
            
PlayerTextDrawColor(playeriddealership_ColorMenu[colorid], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[colorid]);
            return 
1;
            }
        }
    }

Or even this: (This won't work everytime because if you set chosecolorid to 3 for exemple, i think it would give you array index of bounds error)
PHP код:
new colorid GetPVarInt(playerid,"ChoseColorID") + 2
Reply
#5

Quote:
Originally Posted by 10MIN
Посмотреть сообщение
As far as I know if-else is slower or even equally, but not faster. Also pvars are used in gamemode <-> filterscript transition of variables. It could simply be a array.
You could even use the code with ternary operator like this:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_COLORMENU:
        {
            new 
colorid  = (GetPVarInt(playerid"ChoseColorID" == 1)) ? 4;
            
PlayerTextDrawColor(playeriddealership_ColorMenu[colorid], vehicleColoursTableRGBA[strval(inputtext)]);
            
PlayerTextDrawShow(playeriddealership_ColorMenu[colorid]);
            return 
1;
            }
        }
    }

Or even this: (This won't work everytime because if you set chosecolorid to 3 for exemple, i think it would give you array index of bounds error)
PHP код:
new colorid GetPVarInt(playerid,"ChoseColorID") + 2
Wow, that is a more better way than mine.
I'm using this, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)