Little Maths to pawn question...
#1

Hi, I got a little question...
what maths thing do I need to make that per 3 listitems of one dialog represents one index?
so like this:
pawn Код:
if(dialogid == 3290)
    {
        new index;
        if(!response) return 1;
        switch(listitem)
        {
            case 0: index = 1
            case 1: index = 1
            case 2: index = 1
            case 3: index = 2
            case 4: index = 2
            case 5: index = 2
            case 6: index = 3
            case 7: index = 3
        }
but then in one simple line that I do not need to use all this cases...
thanks in advance
plus rep for helper
Reply
#2

pawn Код:
if(dialogid == 3290)
{
    new index;
    if(!response) return 1;
    switch(listitem)
    {
        case 0 .. 2: index = 1
        case 3 .. 5: index = 2
        case 6 .. 7: index = 3
    }
}
You mean this?
Reply
#3

Well according to the pattern there, you've got it so listitems are sorted in indexes of 3. e.g. 0-2 = 1, 3-5 = 2, etc.

So an easier way to get that would be to simply divide the listitem number by 3 then add 1.

pawn Код:
new index = (listitem/3)+1;
Now if you wanted to know which of the 3 the listitem is, you would use this

pawn Код:
new slot = (listitem%3)+1;
This would tell you if it's the first, second, or third of that same index. e.g.

pawn Код:
listitem = 75;
new index = (listitem/3)+1// (25+1) = 26
new slot = (listitem%3)+1// (0+1) = 1
so 75 is the first of index 26
Reply
#4

Wow thats very usefull thanks!
But what woes the percent symbol stand for in this case? For mercent?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)