Here is more of a general question about scripts than one about this specific one, I only take it as an easy example. (Might be stupid questions, but I do not understand it)
We have the following code in Torch.itemScript:
... // irrelevant stuff
ITEM:__Me
EXTERN INT:%StartLit = 0
EVENTS
EVENT InitTorch
ON
OnInit()
VARS
INT:_IsStatusOn
ACTIONS
IF "c1&!c2"
IsEqual(%StartLit,1)
ItemHasStatus(__Me,BURNING)
THEN
ItemApplyStatus(__Me,BURNING)
Set(%StartLit,0)
IF "c1"
GetVar(_IsStatusOn,__Me,"IsStatusOn")
THEN
SetVar(__Me,"IsStatusOn",INT:1)
ENDIF
ELSE
IF "c1&!c2"
GetVar(_IsStatusOn,__Me,"IsStatusOn")
ItemHasStatus(__Me,BURNING)
THEN
SetVar(__Me,"IsStatusOn",INT:0)
ENDIF
ENDIF
...
So I understand that I can have a candle start as lit or unlit.
But what about all those GetVar()s and SetVar()s ?
I thought that all 'VARS' were 'local' variables that exist throughout the function only. (Like auto variables in C)
Do those queries and calls turn them into variables persistent through saves and make a connection between all variables of that name ? (the same variable name is used in all functions in that item script)
The GetVar() in the IF does not make any sense to me, because the queried value is never used in the THEN part (only if it triggered something 'invisible' behind the scenes would it make sense)
Also, simple setting of a value could be done with Set() but here, 'external' calls are used on __Me.
And also, when is OnInit() thrown, only once when the object is created for the first time or on every savegame load as well ?