Every - theRAPTLab/gsgo GitHub Wiki

(See #74)

every

every will run a code block every n seconds.

Syntax

every <interval> <startingState> [[ <code> ]]

Where

  • <interval> is time in seconds (can be a decimal, e.g. 0.5 is half a second)
  • <startingState> is either runAtStart or runAfter

Example

every 5 runAtStart [[ 
  dbgOut 'blip'
]]

runAtStart vs runAfter

The starting state determines when the <code> will fire.

  • runAtStart will fire the code immediately with the first regular game loop.
  • runAfter will fire after the specified interval. e.g. if the line is every 5 runAfter [[ ... ]] the code will run after 5 seconds.

Using every

It MUST be placed in a continuous update loop, e.g. in # PROGRAM UPDATE. (It will NOT run in a # PROGRAM EVENT block.)

IMPORTANT: DO NOT USE THIS in a 'when' BLOCK! It will not do what you expect! The prog code will run for EVERY agent of that blueprint type regardless of whether they match the when condition.

For example:

# PROGRAM UPDATE
every 0.03 [[
  prop agent.energyLevel sub 1
]]

This is the approximate equivalent of:

# PROGRAM EVENT
onEvent Tick [[
  prop agent.energyLevel sub 1
]]

You can specify any number of seconds, or even use floating point seconds. e.g. this will run every half second, or twice a second:

# PROGRAM UPDATE
every 0.5 [[
  prop agent.energyLevel sub 1
]]

It can not fire more frequently than the sim update loop cycle (33ms)

⚠️ **GitHub.com Fallback** ⚠️