This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| functions:cond [2017/03/15 08:45] – created korshun | functions:cond [2017/06/15 12:34] (current) – korshun | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | {{tag> | + | {{tag> |
| - | '' | + | '' |
| [[: | [[: | ||
| - | |||
| - | [[: | ||
| ===== Description ===== | ===== Description ===== | ||
| - | Returns two variables in a swapped order. This function exists | + | If condition is true, returns |
| + | |||
| + | It simulates the ''?:'' | ||
| + | |||
| + | <note important> | ||
| + | < | ||
| + | int y = cond(x, DoSomething(), | ||
| + | </ | ||
| + | as both '' | ||
| + | |||
| + | If you are using [[:BCC]] or [[:GDCC]], it is recommended to use the real ''?:'' | ||
| + | </ | ||
| ===== Examples ===== | ===== Examples ===== | ||
| - | Without swap(): | ||
| < | < | ||
| - | int tmp = x; | + | cond(true, A, B) -> A |
| - | x = y; | + | cond(false, A, B) -> B |
| - | y = tmp; | + | </ |
| + | |||
| + | Without cond(): | ||
| + | < | ||
| + | int color = CR_RED; | ||
| + | if (PlayerTeam() | ||
| + | | ||
| + | DrawSomething(color); | ||
| </ | </ | ||
| - | With swap(): | + | With cond(): |
| < | < | ||
| - | swap(x, y); | + | DrawSomething(cond(PlayerTeam() == TEAM_BLUE, CR_BLUE, CR_RED)); |
| - | x = r1; | + | |
| - | y = r2; | + | |
| </ | </ | ||