VirtualInteger

Function VirtualInteger(varname: string, [createval: Integer=0], [group:Integer=0]) : Integer
Returns the value of the VirtualInteger with name varname.

(For how to use groups, see the advanced topic VirtualVariable Groups)

If a VirtualVariable doesn't exist with that name, a new one is created (in the specified group) with the value of createval. This means that you can add the VirtualVariables to your program with sane default values so that you don't have to define so many settings in script files, but you leave the option there if the settings are needed. This might be useful if you pack all media into one exe but the exe saves its settings after it is run.

Here is an example of a settings file:

# settings.txt
# This is a comment

# Here we define integers (notice the exclaimation mark means integer):
! win_width = 640
! win_height = 480

Here is how it would work in a program:

Program
   Uses
pure2d, basilisk
       
Begin
   InitBasilisk(TRUE)
   ReadSettings("settings.txt")
   
   OpenScreen(VirtualInteger("win_width"), VirtualInteger("win_height"),32,FALSE,COB_SHOWBORDER + COB_SHOWCLOSE)
   FreeVirtualVariables()

   While Not ExitRequested
       Flip
       Pause
(2)
   Wend
   
End

VirtualIntegers can be created either by calling VirtualInteger on a variable that doesn't exist, using the function ReadSettings or the function MapVirtualInteger.

This demonstrates use of the second parameter:

Program
  Uses
pure2d, basilisk
      
Begin
  InitBasilisk(TRUE)
  ReadSettings("non-existant-file.txt")
  OpenScreen(VirtualInteger("win_width",640), VirtualInteger("win_height",480)
  
  // The window still opens at 640x480 even if win_width is never defined by a script file
    
End