Jump to content

Variable initialization assistance


smeagolheart

Recommended Posts

If you want the installer to not die when it tries to call non-existant "%variable%", then VARIABLE_IS_SET check should be enough before proceeding with it. This is handy when the name is dynamic, i.e. you may have no way to initialize it properly.

 

If you actually need to initialize them, then you just have to set them one by one or via some array or loop. Be advised that there's no right way to predict when and where you'll need EVALs for the latter, and how many - in most cases it boils down to trial and error until the code starts working.

Link to comment

You can use VARIABLE_IS_SET to check whether a variable has already been initialized. EVAL should only be used to construct a variable name from a string (which may also contain variable replacements). If "variable" in your example is the actual variable name then EVAL is not needed.

Let's demonstrate it on the following example which initializes the variables "myvar1", "myvar2" and "myvar3" dynamically:

OUTER_SET myvar2 = 1
ACTION_FOR_EACH var IN ~myvar1~ ~myvar2~ ~myvar3~ BEGIN
  ACTION_IF (VARIABLE_IS_SET EVAL ~%var%~) BEGIN
    OUTER_SET result = EVAL ~%var%~
    PRINT ~Variable "%var%" already set to %result%~
  END ELSE BEGIN
    PRINT ~Initializing variable "%var%" to 0~
    OUTER_SET EVAL ~%var%~ = 0
  END
END

ACTION_FOR_EACH var IN ~myvar1~ ~myvar2~ ~myvar3~ BEGIN
  OUTER_SET result = EVAL ~%var%~
  PRINT ~Variable %var% = %result%~
END

It should produce the following result:

Initializing variable "myvar1" to 0
Variable "myvar2" already set to 1
Initializing variable "myvar3" to 0

Variable myvar1 = 0
Variable myvar2 = 1
Variable myvar3 = 0
Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...