Table (decl)

This page is in urgent need of attention because: this page contains unfinished sections

A table declaration is nothing more than a definition of a list of values bound to a name. They are mostly used to iterate a list of common values in materials or GUI scripts . A key example would be lights that fade in and out or strobe in a clear pattern.

Declaration

Declaring a table is fairly simple when you look at the syntax.

table <tablename> { [snap] [clamp] { <data>, <data>, ... } }

The snap and clamp parameters are optional btu can be used together. They are explained in detail in the rest of this article. The data consists of single float values.

Using a table

Square bracket operators are used to get a certain value out of a table. The indexes of the elements start from 0.

tablename [ <expression> ]

The expression between brackets can result in an integer or floating point number. You can use the simple script operators *, %, + and - as well, next to the following predefined variables:

  • time: a floating point value which increases continually as the map progresses.
  • parm0 - parm11: parameters which can be set from script, game code or the map editor.
  • global0 - global7: Unused, although they exist.
  • sound: represents the amplitude of the sound the assigned entity generates. Used for pulsing materials synchronized with the sound.

The expression does not need to result in a real index in the table. If you index an item which does not exist, the game will always return something. The exact behavior is defined by the mentioned snap and clamp parameters.

Snap parameter

If the snap parameter is added, requesting data by the use of a floating point number will always return the item with the nearest index. If the parameter is not set, the game will interpolate between two values.

Let us define two tables:

table squarewave { snap { 0, 1} }
table linearwave { { 0, 1 } }

Now requesting squarewave [ 0.6 ] will return 1, whereas linearwave [ 0.6 ] will return 0.6 because the game interpolates between 1 and 0.

Similarly, squareWave [ 0.3 ] will return 0 and linearWave [ 0.3 ] will return - you guessed it - 0.3.

Clamp parameter

If the clamp parameter is added, requesting an index which is less than 0 or higher than the highest index in the table will return the first, respectively last element from the table. If the parameter is not set, the table will wrap around.

Use in materials

Given the above definitions, we can define a material that uses the current time, combined with the linear table, to fade an overlay image in and out

table linearwave {{ 0, 1 }}

textures/my_textures/fade_in_out
{
    qer_editorimage textures/my_textures/fader.tga

    diffusemap      textures/my_textures/fader.tga

    {
        blend add
        map         textures/my_textures/fader_overlay.tga
        rgb     linearwave[ time * 0.5 ]
        }
}

Use in GUI scripts

This page is a Stub. You can help us by expanding it.

  • Needs some GUI examples. See external links.