On this page:
%const
8.18.0.13

3.8 Constants🔗ℹ

Everything in the game is represented internally by a numeric identifier. A constant is a label that can be used to refer the random map parser to the right item. Many useful objects and terrains have predefined constants (see: Constant Reference). However, many objects and terrains also lack a predefined name. In order to use them in your script, you must first assign a constant to the numeric id.

Note that, unless you need to refer to either predefined constants, predefined entities or use the defined constants in RMS math operations, there is little reason to use these instead of the Racket’s variables.

procedure

(%const const-label const-value)  void?

  const-label : any/c
  const-value : any/c
Game versions: All

Arguments:
  • const-label - text
    • AoC/UP - max length is 99 characters

    • ANY characters are valid; convention is to use uppercase letters and underscores

  • const-value - number (see: Constant Reference)
    • Maximum: 16777216 (2^24)

Assign a label of your choice to a numeric ID, to be able to use the terrain/object associated with that ID.

  • This is required to use anything that is not predefined.

  • Items can have multiple constants assigned to them.

  • You cannot re-define a predefined name to a different ID.

  • DE: You can use #const as a way to define a number. See Math Operations. This WILL work:

  • Pre-DE: You cannot use #const as a way to define a number. This will NOT work:

  • Constants are interpreted in context (ie. in body of create-object the game will interpret it as an object, while in body of create-terrain the game will interpret it as a terrain)
    • WARNING: Constants without a proper context are interpreted as syntax. For more information, see this external article: Parser Pitfalls

Example: Define mossy road so you can use it later.
#lang aoe2-rms
 
(%const 'ROAD_FUNGUS 32)

Example: Define and use variable constants depending on the season.

#lang aoe2-rms
 
(%random [30 (%define 'WINTER)]
         [30 (%define 'AUTUMN)])
 
(%cond ['WINTER
        (%const 'LAND_A 32)
        (%const 'BERRY_TYPE 52)]
       ['AUTUMN
        (%const 'LAND_A 5)
        (%const 'BERRY_TYPE 59)]
       [#f (%const 'LAND_A 3) (%const 'BERRY_TYPE 1059)])
 
<LAND-GENERATION>
(create-player-lands (terrain-type 'LAND_A))
 
<OBJECTS-GENERATION>
(create-object 'BERRY_TYPE
               (number-of-objects 5)
               (set-place-for-every-player)
               (set-gaia-object-only)
               (find-closest)
               (terrain-to-place-on 'LAND_A))