Number Methods - theRAPTLab/gsgo GitHub Wiki

See !110


setToColor method

Colors are implemented as GVar numbers. You could use setTo or setToColor to set a color, the difference being with setTo you would have to enter a number, while with setToColor you would be able to use a color picker.

Syntax

featProp character.Costume.color setToColor <decimal>

Where color is a decimal number corresponding to the hex RGB color. e.g. #FF0000 is 16711680.

setToRnd method

Assigns a property to a random number.

Syntax

The routine accepts multiple syntaxes

prop colorValue setToRnd -- Random value between 0 and 1 prop colorValue setToRnd <max> -- Random value between 0 and <max> prop colorValue setToRnd <min> <max> -- Random value between <min> and <max>


subFloat2 method

A subtraction routine to ensure human-readable floating point numbers to 2 places. This addresses a IEEE 754 Floating point number issue where 0.6 - 0.05 = 0.599999. e.g.:

with sub

prop energyLevel setTo 0.6
prop energyLevel sub 0.05 // => energyLevel = 0.549999

with subFloat2

prop energyLevel setTo 0.6
prop energyLevel subFloat2 0.05 // => energyLevel = 0.50

addRnd and subRnd method

These are convenience methods for adding and subtracting random values to GVarNumbers. This makes it a little easier to do quick calculations without resorting to fancy expressions and stack operations.

Syntax

addRnd and subRnd can take 0, 1, 2, or 3 values.

prop colorValue addRnd <min> <max> <toInteger>

prop colorValue subRnd <min> <max> <toInteger>

where <toInteger> is a boolean. When true, the resulting randomized number will be rounded to the nearest integer.

Example

  • addRnd

    returns a value between 0 and 1. e.g. prop energyLevel addRnd would add a random number between 0 and 1 to energyLevel.

  • addRnd <val>

    returns a value between 0 and the value. e.g. prop energyLevel addRnd 10 would add a random number between 0 and 10 to energyLevel.

  • addRnd <min> <max>

    returns a value between the first (minimum) and second (maximum) values. e.g. prop energyLevel addRnd -50 50 would add a number between -50 and 50 to energyLevel.

  • addRnd <min> <max> <toInteger>

    returns an integer value between the min and max. NOTE to use integers, you MUST set min and max.

In order to support integer random numbers, we've introduced a new flag that can be used with the GVarNumber random number routines. Passing true will force the random number to be an integer.

  • e.g. colorScaleIndex addRnd -2 2 might result in adding 1.8593234
  • e.g. colorScaleIndex addRnd -2 2 true might result in rounding up 1.8593234 to 2.
⚠️ **GitHub.com Fallback** ⚠️