VBScript: set Variables with Underscore

In the FinalBuilder itself there are no problems with $(_abc) and the “Set Variable” action,

but in VBScript such a variable cannot be set.

According to the code completion, there is an FBVariables._abc,
but that’s not true. Luckily there has FBVariables.GetVariable(“_abc”).

But how can this variable to be set?

x = FBVariables._abc  ' does not compile, error message see below 
x = FBVariables.GetVariable("_abc")

Error Executing script : BeforeAction
Compilation error in Microsoft VBScript
invalid symbol
Line: 2
Char : 18
Error in BeforeScript : VBScript, This Action did not execute.

My attempts (can’t find anything else in the code completion, nor anything in the forum or google)

FBVariables._abc = x
FBVariables.GetVariable("_abc") = x
FBVariables.SetVariable("_abc", x)
FBVariables.SetVariable "_abc", x

Action.EnvironmentVariables.Values("_abc") = x   ' this does work, but only for current MSBuild-Action

The codes with FBVariables.GetVariable and FBVariables._abc, in a function in GlobalScript, the execution also breaks off without an error message.
No error message apart from

Error in BeforeScript : VBScript, This Action did not execute.

First thought it was due to SkipAction and had been looking there for ages. :tired_face:

The VBScript language does not allow ‘special’ characters in variables.

This works for me

dim x
Action.SetVariable "_test", "abc"
x = FBVariables.GetVariable("_test")
alert(x)

Not sure why we don’t have Action.GetVariable - we should since actions can implement their own variable namespace (only a few actions do that, like the group). The good news is FBVariables does expose variables via the Action’s variable namespace. Likewise we probably should have FBVariables.SetVariable for consistency.

Unfortunately, Action.SetVariable only sets the variable within the action.
After the action, the variable has its old value again. This is somewhat unfavorable, since the value should be used for many subsequent actions.

I found a preliminary “solution” → a second variable
_test as macro with %dummy_test%
dummy_test for write access in VBScript

I’m not able to reproduce that here.

VBScript_UnderScore.fbp8 (1.3 KB)

In the attached project, the value set in the script is preserved and available in the next action.

Crap, it works in your script.
I was hoping it was because the SetVariable was in a function in ProjectGlobalScript, but unfortunately your script works with that too.

Ah, I found the reason.
The variable is defined as a macro.

It wasn’t the underscore at all. Even with FBVariable.xyz=… it doesn’t work.

Why is it not possible to change the content?
But OK, the SetVariable action doesn’t have such macros in the select list.

Maybe you could throw an error message here when trying to change such macro variables?

We have considered this in the past, however doing so might cause people’s builds to start failing. We’ll look at this for FB9.