The behavior of SET_SCRIPT_VAR is different between V11 and V12 (12.3.4).
With V12, you had to manually initialize the variables before setting a value with the function.
On V11 it was not necessary.
Release : 12.3
Component : AUTOMATION ENGINE
This could have been considered an error in the older versions - v11 and v12.
This was finally fixed/changed in 12.1, so a variable always needs to be defined/initialized before the set_script_var was used.
The current behavior is correct.
The product documentation for set_script_var also includes the following note beginning from v12.1:
You cannot use this script element to create script variables. To do so, use :SET before you use :SET_SCRIPT_VAR.