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
Variable/Gmakes a global number,String/Ga global string.NVARandSVARbind to them from inside a function.- Panels use globals because a control has to write somewhere that lasts.
Keywords and builtins used here
EndFunctionNVARNewDataFolderPrintfSVARStringVariable
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.
Step 1 of 2 in Where data lives, step 16 of 18 in Language basics.