error 001: expected token: ":", but found ")"
#1

PHP код:
    case D_NMENU+3:
        {
            if(!
response) return 1;
            if(
listitem 3)
            {
                new 
string[28];
                
format(stringsizeof(string), "Вы слушаете радио: %s",
                (
listitem == 0) ? ("LS News") : (listitem == 1) ? ("SF News") : (listitem == 2) ? ("LV News"));
                
SendClientMessage(playeridCOLOR_WHITEstring);
                
PI[playerid][pNews] = listitem+1;
            }
            else
            {
                
SendClientMessage(playeridCOLOR_LIGHTRED"Вы выключили радио");
                
PI[playerid][pNews] = 0;
            }
        } 
PHP код:
gamemodes\new.pwn(12537 -- 12538) : error 001expected token":"but found ")" 
Reply
#2

If listitem is 2, it will pass "LV News" as argument, but else is missing even if there is nothing.
pawn Код:
(listitem == 0) ? ("LS News") : (listitem == 1) ? ("SF News") : (listitem == 2) ? ("LV News") : ("N/A"));
But why not just use a simple array?
pawn Код:
new city_news[][] = {"LS News", "SF News", "LV News"};
pawn Код:
format(string, sizeof(string), "Вы слушаете радио: %s", city_news[listitem]);
Reply
#3

BTW, not going in deep, There is an extra ")" in there:-
Код:
                (listitem == 0) ? ("LS News") : (listitem == 1) ? ("SF News") : (listitem == 2) ? ("LV News"));
It should be like:-
Код:
                (listitem == 0) ? ("LS News") : (listitem == 1) ? ("SF News") : (listitem == 2) ? ("LV News");
It was a simple problem.
Reply
#4

The last ")" is part of "format("

Ternary operator is an if-else but with symbols. When using ? for if, there must also be : for else. This is what is missing from his code and the reason I added it at end even if listitem will always be 0-2

It is worth mentioning that if you show a list dialog with 3 lines "LS News\nSF News\nLV News", the inputtext in OnDialogResponse will be the same text from the line you selected. If you use it like this, you do not need ternary or an array- just use inputtext directly.
Reply
#5

You should use switch-case statement instead of using ternary operators here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)