Different errors in matching script
#1

expected token: "-string end-", but found "-identifier-"

pawn Код:
case 2: division = "B" { // Central
invalid function or declaration

pawn Код:
case 3: division = "C" { // Eastern
I get the first error for the first 2 cases, then the second error for every case after that.

Every case within this switch is the same, just a different division string, and different rank strings. Nothing else is changed...

pawn Код:
case 1: division = "A" { // Western
                    switch(PlayerInfo[targetid][pRank])
                    {
                        case 1: rank = "Prob. Officer";
                        case 2: rank = "Snr. Officer";
                        case 3: rank = "Sergeant";
                        case 4: rank = "Inspector";
                        case 5: rank = "Chief Inspector";
                        case 6: rank = "Superintendent";
                        case 7: rank = "Chief Superintendent";
                        default: rank = "OIT";
                    }
                }
Reply
#2

This is not how switch works.

pawn Код:
switch(division) {
    case 'A': {
        (...)
    }
    case 'B': {
        (...)
    }
    default: {
        (...)
    }
}
Also switch _won't work_ with strings. As you can see there is 'A', not "A", so I'm comparing char, not string. You have to use strcmp with if/elseif/else control structure to compare strings.

#e:
In case you want to assign division, simply move the division = X after the curly brace
Reply
#3

That wasn't the problem...

pawn Код:
case 3: division = "C" { // Eastern
Should be written...

pawn Код:
case 3: { division = "C"; // Eastern
That's all it was.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)