ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:cond

This is an old revision of the document!


Table of Contents

cond

any cond(bool condition, any a, any b)

any - any type (int, fixed or str)

Description

If condition is true, returns a. Otherwise, returns b.

It simulates the ?: operator from C.

Both a and b are evaluated. Do not do this:
int y = cond(x, DoSomething(), DoSomethingElse())

as both DoSomething() and DoSomethingElse() will be called.

If you are using GDCC, it is recommended to use the real ?: operator instead, which is not subject to this problem.

Examples

cond(true, A, B) -> A
cond(false, A, B) -> B

Without cond():

int color = CR_RED;
if (PlayerTeam() == TEAM_BLUE)
    color = CR_BLUE;
DrawSomething(color);

With cond():

DrawSomething(cond(PlayerTeam() == TEAM_BLUE, CR_BLUE, CR_RED));
functions/cond.1489567908.txt.gz · Last modified: 2017/03/15 10:51 by korshun