What;s a better way to do this?
#1

So, I don't want to reveal my code but i'll give an example.

What is a less time-consuming, more efficient method of doing this:

pawn Код:
switch(listitem)
                {
                    case 0:
                    {
                        Player[playerid][val] = 1;
                    }
                    case 1:
                    {
                        Player[playerid][val] = 2;
                    }
                    case 2:
                    {
                        Player[playerid][val] = 3;
                    }
                    case 3:
                    {
                        Player[playerid][val] = 4;
                    }
                    case 4:
                    {
                        Player[playerid][val] = 5;
                    }
                    case 5:
                    {
                        Player[playerid][val] = 6;
                    }
                    case 6:
                    {
                        Player[playerid][val] = 7;
                    }
                    case 7:
                    {
                        Player[playerid][val] = 8;
                    }
                    case 8:
                    {
                        Player[playerid][val] = 9;
                    }
                    case 9:
                    {
                        Player[playerid][val] = 10;
                    }
                    case 10:
                    {
                        Player[playerid][val] = 11;
                    }
                    case 11:
                    {
                        Player[playerid][val] = 12;
                    }
                }
Reply
#2

You could do;

pawn Код:
Player[playerid][val] = listitem + 1;
Reply
#3

I am not sure if this what you are looking for, but you could do something like this.

pawn Код:
Player[playerid][val] =  listitem + 1;
Quote:
Originally Posted by Emmet_
Посмотреть сообщение
You could do;

pawn Код:
Player[playerid][val] = listitem + 1;
Fuck late! Emmet sucks! :P
Reply
#4

Say the listitem was 4.

That would mean the value is 5, yeah? If so that's what I'm looking for
Reply
#5

Quote:
Originally Posted by sammp
Посмотреть сообщение
Say the listitem was 4.

That would mean the value is 5, yeah? If so that's what I'm looking for
Exactly.
Reply
#6

Also, instead of this:

pawn Код:
stock TranslateMonth(playerid)
    {
        new s[4], m;
        m = Player[playerid][bMonthNumber];

        if(m == 1)format(s, sizeof(s), "January");
        if(m == 2)format(s, sizeof(s), "February");
        return 1;
    }
Can it be put into an array and done that way rather than a stock? if so can you provide evidence
Reply
#7

Quote:
Originally Posted by sammp
Посмотреть сообщение
Also, instead of this:

pawn Код:
stock TranslateMonth(playerid)
    {
        new s[4], m;
        m = Player[playerid][bMonthNumber];

        if(m == 1)format(s, sizeof(s), "January");
        if(m == 2)format(s, sizeof(s), "February");
        return 1;
    }
Can it be put into an array and done that way rather than a stock? if so can you provide evidence
Enjoy!

pawn Код:
stock TranslateMonth(playerid)
{
    new s[12], m;
    m = Player[playerid][bMonthNumber];

    switch(m) {
        case 1: format(s,sizeof(s),"January");
        case 2: format(s,sizeof(s),"February");
        case 3: format(s,sizeof(s),"March");
        case 4: format(s,sizeof(s),"April");
        case 5: format(s,sizeof(s),"May");
        case 6: format(s,sizeof(s),"June");
        case 7: format(s,sizeof(s),"July");
        case 8: format(s,sizeof(s),"August");
        case 9: format(s,sizeof(s),"September");
        case 10: format(s,sizeof(s),"October");
        case 11: format(s,sizeof(s),"November");
        case 12: format(s,sizeof(s),"December");
    }
    return s;
}
Reply
#8

pawn Код:
stock TranslateMonth(playerid)
{
    new s[10];

    switch(Player[playerid][bMonthNumber])
    {
        case 1: s = "January";
        case 2: s = "February";
        case 3: s = "March";
        case 4: s = "April";
        case 5: s = "May";
        case 6: s = "June";
        case 7: s = "July";
        case 8: s = "August";
        case 9: s = "September";
        case 10: s = "October";
        case 11: s = "November";
        default: s = "December";
    }
    return s;
}
Reply
#9

What Jefff said, or:
pawn Код:
stock const szMonthNames[12][10] =
{
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
};

// Somewhere in a function:
new szMessage[48];
format(szMessage, 48, "Month name: %s", szMonthNames[--Player[playerid][bMonthNumber]]);
You said you wanted it without a stock.
I propose this way over any other, it's the fastest, but be careful that "bMonthNumber" is an integer between 1..12 (and also never 0!)
and if it's not you shouldn't execute the code I posted as an example.
Reply
#10

I'll use your method, Vitrual1ty.

The number is never 0, except from when they've not inputted a month. Which I can adjust if need be.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)