ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


multiple_return_values

This is an old revision of the document!


Multiple return values convention

Some ACSUtils functions return multiple values (e.g. vector math functions, but also some non-math functions). ACS doesn't support returning multiple values from a function.

ACSUtils uses a convention to fake returning multiple values from a function. The convention is as follows: there are 8 global variables with names r1 through r8. If a function returns multiple values, it actually returns no value and writes the first “returned” value to r1, the second one to r2, and so on.

Here's an example, RotateVector returns X and Y:

RotateVector(x, y, angle);
int newX = r1;
int newY = r2;
You should retrieve the return values as soon as possible, or else they may get overwritten by other functions that return multiple values.

Don't do this:

SomeFunctionWithMultipleReturnValues(...);
SomeOtherFunction(r1);
int b = r2;

Because SomeOtherFunction may call functions that overwrite r2! Instead, strictly follow this style:

SomeFunctionWithMultipleReturnValues(...);
int a = r1;
int b = r2;

SomeOtherFunction(a);

But overwriting argument variables immediately after calling the function is valid:

RotateVector(x, y, angle);
x = r1;
y = r2;

An example of a function returning three values:

normalize3d(x, y, z);
int newX = r1;
int newY = r2;
int newZ = r3;
multiple_return_values.1555702677.txt.gz · Last modified: 2019/04/19 22:37 by korshun