Skip to content

Types of values

CPU edited this page Jan 3, 2021 · 11 revisions

The RGE language has only 3 native types:

  • int
  • float
  • string

The values for the ints can be written as hexadecimal prepending them by 0x (0x40 is equal to 64)

Another special format is the color that is written as a c and 3 or 4 numbers between 0 and 3. For example c330 is yellow and c300 is red. Check [insert section link] Colors for a full description. A color is just an int with 8 bits (a byte) of value.

A variable can keep any of these values, the variables are soft-typed like Javascript.

A value in a variable or an expression can also be "casted".

  • <expression>_b will transform the expression to an int and will return only the less significant byte.
  • <expression>_i will transform the value to an int. In case the expression was a string, the string will be parsed as int.
  • <expression>_f will transform the expression to a float
  • <expression>_s will transform the expression to a string

It is possible to access the memory (Ram and Rom) using the format: [adderss]
The result is the value contained in memory at the specified address.
Of course, the address can be calculated like any expression.

A specific way to access well defined memory addresses of the Rom is to use the Labels that can be defined in the Data section. For example: sprite 1, SpriteDef: is using the label SpriteDef: and defines the texture of the sprite #1 as starting from label SpriteDef.

The values from the memory are accessed by default as bytes.
You can access them as int, float, and strings. To do so use the following notation:

  • [<address>@] to access it as int
  • [<address>@b] to access it as byte
  • [<address>@i] to access it as int (same as just using @)
  • [<address>@f] to access it as float
  • [<address>@s] to access it as string

Be aware that if you assign a string to the memory, the first 2 bytes of the value will contain the length of the string. Converting a memory address to a string will work only if the first two bytes contain the length of the expected string.
Example:
[10] = "ABC"
Will have at memory location 10 the value 0 and at memory location 11 the value 3 (the length of the string is 3), and then at location 12 the value 65 that is the numeric format ot UTF8 for the letter A.

Clone this wiki locally