SetEnv env_var$,value$
Parameters
|
env_var$ - name of the environment variable to write value$ - value to store; an empty string deletes the variable |
Description
|
Stores a value in an environment variable. The variable lives in your program's own environment block. Nothing outside the program sees it: your desktop, the IDE and any application already running keep their own copy, and everything you set here is thrown away when the program ends. What SetEnv is genuinely useful for is passing settings on to a program you start yourself - child processes inherit the environment as it stands at the moment they are launched, so a SetEnv before ExecFile is a tidy way to hand a level name, a server address or a debug flag to a tool, a patcher or a second copy of your game. Writing a name that already exists simply replaces the old value. Writing an empty string removes the variable altogether, so GetEnv then returns "" again - that is the clean-up call after a temporary setting. Names are not case sensitive on Windows. Values are plain text, so numbers need converting on the way back in. Avoid stamping on well-known system variables such as PATH or TEMP unless you really mean to; a child process that inherits a broken PATH may fail in confusing ways. See also: GetEnv, ExecFile, CommandLine, SystemProperty. |
Example
; SetEnv Example ; -------------- ; SetEnv stores a value in this program's environment block. ; Child programs started later inherit it, so it is a simple way to ; hand a setting to a tool or level editor you launch with ExecFile. Print "Before : ["+GetEnv$("BLITZ3D_DEMO_MODE")+"]" ; Store a value SetEnv "BLITZ3D_DEMO_MODE","normal" Print "Set 'normal': ["+GetEnv$("BLITZ3D_DEMO_MODE")+"]" ; Writing again simply replaces the old value SetEnv "BLITZ3D_DEMO_MODE","nightmare" Print "Overwritten : ["+GetEnv$("BLITZ3D_DEMO_MODE")+"]" ; An empty value deletes the variable, which is how you clean up SetEnv "BLITZ3D_DEMO_MODE","" Print "Cleared : ["+GetEnv$("BLITZ3D_DEMO_MODE")+"]" Print "" Print "The change lives inside this program only - your desktop and" Print "any program already running keep their own environment." Print "" Print "Press any key to close the example" WaitKey End
Index