Ternary Operator
#1

Code:
new gender[16];
new IsPlayerMale = (IsPlayerMale(playerid)) ? format(gender, sizeof(gender), "Male") : format(gender, sizeof(gender), "Female"); // 429
Code:
(429) : error 012: invalid function call, not a valid address
(429) : warning 215: expression has no effect
(429) : error 001: expected token: ";", but found ")"
(429) : error 029: invalid expression, assumed zero
(429) : fatal error 107: too many error messages on one line
Not sure why this won't work. First time using the Ternary Operator.
Reply
#2

The problem isn't with the ternary operator. You have given the variable the same name as the function.

pawn Code:
new isMale = (IsPlayerMale(playerid)) ? format(gender, sizeof(gender), "Male") : format(gender, sizeof(gender), "Female"); // 429
isMale won't actually contain a useful value; it will just be whatever format returns. If you need to use format, then in this case you may as well just use a normal if/else statement.

Otherwise, this is how you use strings in a ternary operator:
pawn Code:
new gender[7];
gender = IsPlayerMale(playerid) ? ("Male") : ("Female");
Reply
#3

Ah, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)