typestar

Globals in Igor Pro

A global lives in a data folder; NVAR and SVAR are the references that reach it.

Function InitSettings()
    NewDataFolder/O root:Settings
    Variable/G root:Settings:gThreshold = 0.5
    String/G root:Settings:gLastFile = ""
End

Function UseSettings()
    NVAR threshold = root:Settings:gThreshold
    SVAR lastFile = root:Settings:gLastFile

    threshold *= 2
    lastFile = "run_012.ibw"

    Printf "threshold now %g\r", threshold
End

How it works

  1. Variable/G makes a global number, String/G a global string.
  2. NVAR and SVAR bind to them from inside a function.
  3. Panels use globals because a control has to write somewhere that lasts.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
328
Tokens
59
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 44 seconds.

Type this snippet

Step 1 of 2 in Where data lives, step 16 of 18 in Language basics.

← Previous Next →