error 001: expected token: ":", but found ")" - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: error 001: expected token: ":", but found ")" (
/showthread.php?tid=655725)
error 001: expected token: ":", but found ")" -
sanight - 28.06.2018
PHP код:
case D_NMENU+3:
{
if(!response) return 1;
if(listitem < 3)
{
new string[28];
format(string, sizeof(string), "Вы слушаете радио: %s",
(listitem == 0) ? ("LS News") : (listitem == 1) ? ("SF News") : (listitem == 2) ? ("LV News"));
SendClientMessage(playerid, COLOR_WHITE, string);
PI[playerid][pNews] = listitem+1;
}
else
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Вы выключили радио");
PI[playerid][pNews] = 0;
}
}
PHP код:
gamemodes\new.pwn(12537 -- 12538) : error 001: expected token: ":", but found ")"
Re: error 001: expected token: ":", but found ")" -
Calisthenics - 28.06.2018
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]);
Re: error 001: expected token: ":", but found ")" -
TheBeastKhan - 28.06.2018
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.
Re: error 001: expected token: ":", but found ")" -
Calisthenics - 28.06.2018
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.
Re: error 001: expected token: ":", but found ")" -
Dayrion - 28.06.2018
You should use switch-case statement instead of using ternary operators here.