# Global functions (ZScript)

ZScript provides several built-in functions. Most of these functions are mathematical in nature, but a few allow you to control the execution of scripts or perform graphics operations.

## Contents

- 1 Math and Trig Functions
- 1.1 float Abs(float val)
- 1.2 float ArcTan(int X, int Y)
- 1.3 int Ceiling(int x)
- 1.4 float Cos(int deg)
- 1.5 int Distance(int x1, int y1, int x2, int y2)
- 1.6 int Div(int x, int y)
- 1.7 int Factorial(int val)
- 1.8 int Floor(int x)
- 1.9 int InvPow(int base, int exp)
- 1.10 float Log10(float val)
- 1.11 float Ln(float val)
- 1.12 float Max(float a, float b)
- 1.13 float Min(float a, float b)
- 1.14 int Pow(int base, int exp)
- 1.15 float RadianCos(float rad)
- 1.16 float RadianSin(float rad)
- 1.17 float RadianTan(float rad)
- 1.18 int Rand(int maxvalue)
- 1.19 float Sin(int deg)
- 1.20 float Sqrt(float val)
- 1.21 float Tan(int deg)

- 2 Script Execution
- 3 Graphics

## Math and Trig Functions

### float Abs(float val)

Return the absolute value of the parameter, if possible. If the absolute value would overflow the parameter, the return value is undefined.

### float ArcTan(int X, int Y)

Returns the angle of a line with the slope Y/X. (Now confirmed Joe123 00:22, 7 June 2008 (PDT))

- Introduced in Version

2.5 (beta, build 780)

### int Ceiling(int x)

Rounds a floating point number up to the nearest integer value. This function is defined in std.zh.

### float Cos(int deg)

Returns the trigonometric cosine of the parameter, which is interpreted as a degree value.

### int Distance(int x1, int y1, int x2, int y2)

Returns the distance between the two points (x1,y1) and (x2, y2). This function is defined in std.zh.

### int Div(int x, int y)

Performs integer division - returns an integer value for x/y. This function is defined in std.zh.

### int Factorial(int val)

Returns val!. The return value is undefined for val <= 0 (despite the convention 0! = 1.)

### int Floor(int x)

Rounds a floating point number down to the nearest integer value. This function is defined in std.zh.

### int InvPow(int base, int exp)

Returns base^(1/exp). The return value is undefined for exp=0, or if exp is even and base is negative. Note also that negative values of exp may not be useful, as the return value is truncated to the nearest integer.

### float Log10(float val)

Returns the log of val to the base 10. Any value <= 0 will return 0.

### float Ln(float val)

Returns the natural logarithm of val (to the base e). Any value <= 0 will return 0.

### float Max(float a, float b)

Returns the greater of a and b.

### float Min(float a, float b)

Returns the lesser of a and b.

### int Pow(int base, int exp)

Returns base^exp. The return value is undefined for base=exp=0. Note also negative values of exp may not be useful, as the return value is truncated to the nearest integer.

### float RadianCos(float rad)

Returns the trigonometric cosine of the parameter, which is interpreted as a radian value.

### float RadianSin(float rad)

Returns the trigonometric sine of the parameter, which is interpreted as a radian value.

### float RadianTan(float rad)

Returns the trigonometric tangent of the parameter, which is interpreted as a radian value. The return value is undefined for values of rad near (pi/2) + n*pi, for n an integer.

### int Rand(int maxvalue)

Computes and returns a random integer i such that 0 <= i < maxvalue. The return value is undefined if maxvalue is 0 or negative.

### float Sin(int deg)

Returns the trigonometric sine of the parameter, which is interpreted as a degree value.

### float Sqrt(float val)

Computes the square root of the parameter. The return value is undefined for val < 0.

### float Tan(int deg)

Returns the trigonometric tangent of the parameter, which is interpreted as a degree value. The return value is undefined if deg is of the form 90 + 180n for an integral value of n.

## Script Execution

#### void ClearTrace()

Clears allegro.log of all current traces and messages from Zelda Classic and ZQuest.

- Introduced in Version

2.5 (beta 1056)

### void Quit()

Terminates execution of the current script. Does not return.

- Introduced in Version

2.5 (beta)

### void Trace(float val)

Prints a line containing a string representation of val to allegro.log. Useful for debugging scripts.

- Introduced in Version

2.5 (beta)

#### void TraceB(bool state)

Traces a line containing a string representation of state as a boolean value to allegro.log. Useful for debugging scripts.

- Introduced in Version

2.5 (beta 1056)

#### void TraceNL()

Traces a new line to allegro.log.

- Introduced in Version

2.5 (beta 1056)

#### void TraceToBase(float val, int base, int mindigits)

Prints a line allegro.log. representing 'val' in numeric base 'base', where 2<=base<=36, with at least 'mindigits' number of digits.

- Introduced in Version

2.5 (beta 1056)

#### void TraceS(int[] s)

Takes the array pointer as its argument, and prints it as a string to allegro.log. Maximum 512 characters

- Introduced in Version

2.5 (beta 1213)

### void Waitdraw()

Temporarily halts execution of the current script until after the other game processing is done, but before the screen is rendered.

- Introduced in Version

2.5 (beta, build 776)

### void Waitframe()

Temporarily halts execution of the current script to allow the Zelda Classic game engine to perform its game-related processing.

Global scripts and freeform combo scripts can be made to execute during multiple frames of gameplay; for these types of scripts, when Waitframe() is called control is returned to the script at the beginning of the next frame of gameplay. Item scripts only execute for one frame, however, so in those scripts Waitframe() is essentially Quit(). See The Deliberately Infinite Loop.

- Introduced in Version

2.5 (beta)

### void Waitframes(int j)

Temporarily halts execution of the current script for the specified number of frames. See Waitframe(). This function is defined in std.zh.

## Graphics

### void ClearTile(int tileref)

Erases the tile specified by tileref.

- Introduced in Version

2.5 (beta, build 758)

### int ComboAt(int x, int y)

Returns the address of the Combo that contains the specified point (x,y). See Combo Addressing. This function is defined in std.zh.

### void CopyTile(int srctile, int desttile)

Copies the tile specified by scrtile onto the tile space specified by desttile.

- Introduced in Version

2.5 (beta, build 758)

### void SwapTile(int firsttile, int secondtile)

Swaps the two tiles specified by firsttile and secondtile.

- Introduced in Version

2.5 (beta, build 758)