character variables - GregHib/void GitHub Wiki

Both Players and NPCs have a Variables container for storing variables and information.

By default variables are only stored temporarily and will be lost/reset when the npc dies, player logs out, or the game restarts.

Variable names should use lower camel case. e.g. "in_combat" not "inCombat"

Getters

Characters have extension functions to simplify accessing Variables

The following safe version will return false if the value is unset.

val burrow = giantMole["burrow", false]

Tip

Providing a default is the recommended way of accessing values.

val burrow: Boolean = giantMole["burrow"]

Warning

This is the unsafe version and will throw an exception is the value hasn't previously been set and doesn't have a default listed in the variables config file.

Setters

Setting a value is straight-forward, it's important to use descriptive names to make sure values don't conflict with other content.

giantMole["burrow"] = true

Player variables

Variables which a player has often need to be sent to the client to change something or display the value. Client variables are split into one of 4 categories:

  • varp - Player Variable
  • varbit - Variable Bit (part of a varp)
  • varc - Client Variable
  • varcstr - Client String Variable

Any variables which need storing but don't have a known id should be stored in variables-custom.yml

For more details read Runelites page on the subject

These variables will need specifiying in the relevant variables- yaml file in ./data/definitions/. Along with their id and type.

cooks_assistant:      # The string name of the variable
  id: 29              # The variable id to send to the cleint
  persist: true       # Save the value on logout
  format: map         # The format the value is stored in (might differ from the format sent to the client)
  default: unstarted  # The default value if left unset
  values:             # Map for converting values before sending to client
    unstarted: 0
    started: 1
    completed: 2
⚠️ **GitHub.com Fallback** ⚠️