ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:cond

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 BCC or 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.txt · Last modified: 2017/06/15 15:34 by korshun