Manual VirtualVariable Overrides
Using the MODE Parser Function to set the ALWAYS_OVERRIDE_DUPLICATES Engine Mode to FALSE, you are put into manual override mode.
The way this works is that when reading a script, if the program comes across a VirtualVariable with the same name as an existing one, it deletes the old one and creates the new one when ALWAYS_OVERRIDE_DUPLICATES is TRUE.
When it is FALSE, there is no check if VirtualVariables already exist. This increases performance, and also allows you to load several VirtualVariables with the same name, and loop through them.
Here's an example of a script where performance is increased by turning ALWAYS_OVERRIDE_DUPLICATES off, but overrides have to be forced with the asterisk:
: MODE = (ALWAYS_OVERRIDE_DUPLICATES, FALSE)
! myint = 5
# This has to be a forced override,
# otherwise VirtualInteger("myint")
# will return the first value it finds,
# which will be 5
!*myint = myint + 1
Here's an example where values are purposefully stacked for looping:
# stackexample.txt
: MODE = (ALWAYS_OVERRIDE_DUPLICATES, FALSE)
$ data = (fred, 17)
$ data = (tom, 11)
$ data = (billy, 23)
$ data = (sally, 78)
$ data = (fran, 42)
# Back to normal behaviour
: MODE = (ALWAYS_OVERRIDE_DUPLICATES, TRUE)
# Continue loading stuff...
The code:
Program
Uses basilisk, pure2d
Var
y : Integer
str : String
Begin
InitBasilisk(TRUE)
OpenScreen(640,480,32,FALSE,COB_SHOWCLOSE+COB_SHOWBORDER)
ReadSettings("stackexample.txt")
While VirtualVariableExists("data")
str = ExpressionParameters(VirtualString("data"))
Text(10,10+y,"Name: "+ParameterAsString(str,1))
Text(200,10+y,"Age: "+ParameterAsString(str,2))
FreeVirtualVariable("data")
y = y + 20
Wend
While Not ExitRequested
Flip
Pause(2)
Wend
End