Quote:
Originally Posted by newbienoob
Can I use ternary operator, bit-flags and multiple actions in one statement together? I mean like;
pawn Код:
//normal if-else statement if(a == 0) a = 1; SetPlayerHealth(playerid, 100); else a = 0; SetPlayerHealth(playerid, 0);
//ternary operator with multiple actions a = (a == 0) ? 1, SetPlayerHealth(playerid, 100), print("Health: 100") : 0, SetPlayerHealth(playerid, 0), print("Health: 0"); //not sure here. correct me if I'm wrong
//and how can I use bit flags with ternary operator? enum test: (<< = 1) { a, // question here; what happen if i dont put = 1? like a = 1, b } new test:player[MAX_PLAYERS]; //so i want to toggle a to 0 or 1 using ternary operator. how can i do that?
|
All of these questions you can answer yourself by testing it out, fyi.
pawn Код:
a = (a == 0) ? 1, SetPlayerHealth(playerid, 100), print("Health: 100") : 0, SetPlayerHealth(playerid, 0), print("Health: 0");
That might work, but even if it does it's horribly confusing!
pawn Код:
enum test: (<< = 1)
{
a, // question here; what happen if i dont put = 1? like a = 1,
b
}
All of them will have value 0 because 0 << 1 is still 0.
pawn Код:
new test:player[MAX_PLAYERS];
//so i want to toggle a to 0 or 1 using ternary operator. how can i do that?
Not sure what you mean. Start off from the examples in the main post and work your way from there. You'll figure it out.
If you need a place to quickly test things, use this:
http://slice-vps.nl:7070/