Shouldn't the below script be getting the variable the button declared with @set?
I'm not trying to pass information to the script I could use arguments (template) for that. I'm trying to return a value from the script. Although I haven't tried I could probably get it working another way by using other variable scopes such as Tab (src:) etc. Maybe a bug?
Button
@set var_test=testing123
VarTest
Script
function OnInit(init)
{
init.name = "Command local var test";
init.default_enable = true;
var cmd = init.AddCommand();
cmd.name = "VarTest";
cmd.label = "VarTest";
cmd.method = "VarTest";
return false;
}
function VarTest(data)
{
DOpus.Output(data.Func.Command.Vars.Get("var_test")); // doesn't return "testing123"
DOpus.Output(data.Func.Command.Vars.count); // returns count of 0
}
var cmd = DOpus.Create().Command;
var command = '';
// set global variable for button
command = '@set glob:variable_for_button=true';
cmd.AddLine(command);
cmd.Run();
cmd.UpdateToggle();
to set a global variable that can be picked up from a Standard Function Button like so @icon:tick,$glob:variable_for_button
in your code above the Varsvar_test is not being set anywhere.
@galaxyhub Right, thanks for the response. For what I'm using it for I don't need a global variable. I could use global in the meantime as a workaround or one of the other variable scopes. I'm just bringing to the DOpus devs attention that Command.vars isn't working (assuming it works as I think it does).
In my example above I set the variable first and then ran the script command. I think I should be able to just run the script command and set the local variable from within the command and be able to test it after the command completes with @if: in the button. I haven't tested this with Lister.vars and Tabs.vars but have with DOpus.vars in the past, presumably it should work the same for Command.vars along with all the other variable scopes from a script.
Thanks, Fixed! The variable needs to be declared first though in the command. Is that just how the Command.vars work versus the other scopes? With the others you can set them only in the script and they are available in the command without ever using @set. Example below.
Button
//@set $var_test=testing123
// Following line works too even though it should remove the var
//@set $var_test
VarTest
// Output vars set from script
@output:{$glob:var_test} // Success
@output:{$lst:var_test} // Success
@output:{$src:var_test} // Success
@output:{$var_test} // Failed unless it's set first (commented above)
// Remove vars set from script
@set $glob:var_test
@set $lst:var_test
@set $src:var_test
Script
function OnInit(init)
{
init.name = "Command local var test";
init.default_enable = true;
var cmd = init.AddCommand();
cmd.name = "VarTest";
cmd.label = "VarTest";
cmd.method = "VarTest";
return false;
}
function VarTest(data)
{
DOpus.vars("var_test") = "GlobalVar";
DOpus.Listers(0).vars("var_test") = "ListerVar";
data.Func.sourcetab.vars("var_test") = "SourceVar";
data.Func.Command.vars("var_test") = "CommandVar";
}
Output from button:
GlobalVar
ListerVar
SourceVar (blank line)