smeagolheart Posted August 17, 2016 Share Posted August 17, 2016 I've got to initialize 97 variables to zero. I am not thrilled looking at 97 outer_set variable = 0s. I tried: ACTION_IF EVAL "%variable%" = "" BEGIN OUTER_SET EVAL "%variable%" = 0 But that doesn't work. Anyway ideas? Link to comment
Ardanis Posted August 18, 2016 Share Posted August 18, 2016 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
argent77 Posted August 18, 2016 Share Posted August 18, 2016 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
smeagolheart Posted August 18, 2016 Author Share Posted August 18, 2016 that did the trick thanks guys. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.