Variable variable names

I've got a number of FinalBuilder variables to control which packages get built in my FinalBuilder script. Their names are like %Build_connect-core% for the connect-core package, %Build_connect-admin% for connect-admin, %Build_mydns-mysql% for the mydns-mysql package, etc.

 

I've just written a perl script that gives me a list of packages that need to be built. I'd like to be able to set the Build_* variables based on the list of packages, so if I see "connect-core" in the list I want to set %Build_connect-core% to "True" (they all default to "False"). I was thinking of using a list iterator on the list of packages, putting each package name in turn in a %TEMP% variable, and then somehow setting the appropriate Build_* variable based on what is in %TEMP%. I could have a whole bunch of if ... Then actions, one for each possible package, but that's pretty inelegant and makes it a pain when we add more packages. It seems like there ought to be a better way.

 

Is there a way to Create a variable name in a variable, and then assign to the name I just created? Basically, if %TEMP% contains "connect-core", I want to assign "%%Build_%TEMP%%%" to a variable, so its value ends up being "%Build_connect-core%" and then use that as a reference to the real variable that I want to set to "True". I know I can use that sort of constuct on the "right side" of an assignment, but is there a way to create an lvalue at runtime?

 

Or is there a better way? In perl I'd use a hash called %Build and just say $Build{$TEMP} = True. Is there equivalent functionality in Finalbuilder that I've missed?

 

Thanks,

    Keith

 

Hi Keith,

A while ago I was thinking about how you would put together a project to demonstrate that FinalBuilder is Turing complete. This isn't it, but it reminded me of it.
(/DorkyComputerScienceTalk)

Anyhow, I've attached a demo project which shows how to set individual variables based on the contents of a list, by using some JScript to edit the VariableName property of a Set Variable action. Normally, you could just set the variable name to be Build_%ProjectName%. However, in the case of the Set Variable action, variable names are not expanded and the field isn't normally editable, so the JScript is required.

 

Another alternative could be to write a simple ActionStudio action in JScript. Please let us know how you go.

 

Regards,

Angus

DynamicVariables.zip (2.442 KB)


That works perfectly. Thanks a lot!

Keith