MODIFY VALUE OF AN APPLICATION OBJECT WITHIN SCRIPT

I have a variable:
public string test = "MyString";
I registered it as a Global Item:
scriptRun.GlobalItems.Add(new ScriptGlobalItem("test", typeof(string), test));
I change the value of the variable within the script, but when the script ends, the value of the variable remains the same.
Inside script:
public void CatchButton()
{
ScriptGlobalClass.RunButton.Text = "Catch me if you can";
ScriptGlobalClass.test = "Follow me";
}
What do I need to do to be able to change a value of an application object within the script?
Hello Rogerio,
To access objects in script, we create static class, with fields in it. When fields are assigned to some other values, that does not affect original variable:
Here is code snippet to illustrate this behaviour.
public static class Test
{
public static string Text;
}
void test()
{
string text = "hello";
Test.Text = text;
Test.Text = "other value";
if (text == Test.Text)
return;
}
Instead you can wrap your string variable in the object, and pass it there:
public class StringWrapper
{
string Value;
}
public StringWrapper test = new StringWrapper {Value = "MyString"};

scriptRun.GlobalItems.Add(new ScriptGlobalItem("test", typeof(StringWrapper), test));
Inside script:
public void CatchButton()
{
ScriptGlobalClass.test.Value = "Follow me";
}
regards,
Andrew