Make an ARC Skill

Example: Global Script Variables

The ARC variable manager stores and retrieves global variables that are available within ARC plugins and controls. This allows you to Set and Get variables that other controls may be configuring or using.

Data Types The script variable stores dynamic data types. This means that there is no declaration between numeric or string values. For example in JavaScript you would type...


setVar("$a", 3);
setVar("$b", 3.123);
setVar("$c", "This is a string");
setVar("$d", 0x55);

And in C# plugin you would type...


ARC.Scripting.VariableManager.SetVariable("$a", 3);
ARC.Scripting.VariableManager.SetVariable("$b", 3.123);
ARC.Scripting.VariableManager.SetVariable("$c", "This is a string");
ARC.Scripting.VariableManager.SetVariable("$d", 0x055);

Single Variables ARC.Scripting.VariableManager.ClearVariable(string variableName) Clear the variable and remove it from memory.

ARC.Scripting.VariableManager.ClearVariables() Clear the entire variable memory.

ARC.Scripting.VariableManager.DoesVariableExist(string variableName) Returns a Boolean if the variable has been defined in memory.

ARC.Scripting.VariableManager.DumpVariablesToString() Returns a string with each variable and the corresponding value (one per line). This is similar to the Variable Manager control found in EZ-Builder->Add Control->Scripting->Variable Manager.

ARC.Scripting.VariableManager.GetVariable(string variableName) Get the value stored in the specified variable.

ARC.Scripting.VariableManager.GetVariable(string variableName, int index) Get the value stored in the specified index of the array variable.

ARC.Scripting.VariableManager.SetVariable(string variableName, object value) Set the value into the memory location of the specified variable. If the variable does not exist, this will create the variable and assign the value.

Array Variables ARC.Scripting.VariableManager.AppendToVariableArray(string variableName, object value) Append the value to the existing array.

ARC.Scripting.VariableManager.CreateVariableArray(string variableName, byte[] values) ARC.Scripting.VariableManager.CreateVariableArray(string variableName, string[] values) ARC.Scripting.VariableManager.CreateVariableArray(string variableName, object defaultValue, int size) Create an array variable and specify the default values. Use AppendToVariableArray() to add more items to this array.

ARC.Scripting.VariableManager.FillVariableArray(string variableName, object defaultValue) If a variable array already exists, this will fill every defined index of the array with the specified value.

ARC.Scripting.VariableManager.GetArraySize(string variableName) Returns an integer that is the index size of the specified array variable.

ARC.Scripting.VariableManager.IsVariableArray(string variableName) Returns a Boolean if the specified variable is an array.

ARC.Scripting.VariableManager.SetVariable(string variableName, object value, int index) Set the value into the index of the specified array variable. The array size must already be defined. If you attempt to set a value to an index outside of the index size, an exception will be thrown.

Monitoring Variable Changes The variable manager has an event which will be raised for any variable changes. If your plugin has a variable that you wish to watch for changes, subscribe to the event. Remember to unsubscribe from the event when your plugin closes, as per the plugin Compliance section of this tutorial. Below is an example of subscribing, checking for a variable change, and unsubscribing when the plugin closes.

If the variable is an array, the index will be populated with the array index that has changed. If the variable is not an array, the index will equal -1.


private MyForm() {

  InitializeComponent();

  // Subscribe to variable change event
  ARC.Scripting.VariableManager.OnVariableChanged += VariableManager_OnVariableChanged;
}

private void FormMain_FormClosing(object sender, FormClosingEventArgs e) {

  // Unsubscribe to variable change event
  ARC.Scripting.VariableManager.OnVariableChanged -= VariableManager_OnVariableChanged;
}

private void VariableManager_OnVariableChanged(string variableName, object value, int index) {

  if (!variableName.Equals("$myVariable", StringComparison.InvariantCultureIgnoreCase))
    return;

  // Do something because the variable has changed
}


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

United Kingdom
#1  

Is this out of date? There doesn't seem to be a GetConfiguration function within EZ_Builder.Config.Sub.PluginV1

PRO
Synthiam
#2  

Look at the tutorial step titled Code: Saving/Loading Configuration

The get and set configuration methods are overrides of the form. There’s a great video on the first step of this tutorial that demonstrates the step by step of building a plugin. I recommend watching that because it helps fill in any steps that were missed.

When you’ve done it once, it makes sense and voila, you can rinse and repeat:)

United Kingdom
#3  

Excellent, thanks - I will do. I really must learn not to just jump ahead in the process:)

PRO
Synthiam
#4  

Hey no problem - I do it all the time, and end up frustrated because I dont know what it was that I missed. Excitement gets the best of me

United Kingdom
#5  

Trying to follow the tutorials but can't find where the plugin page has gone. How do I add a new plugin to the ez-robot / Synthiam site to get the XML?

United Kingdom
#6  

Never mind. Just found the "Create skill control" link:)

#7  

I am trying to follow the instructions for adding my own plugin but I cannot seem to find the place to register the plugin based on the instructions.

Any help is appreciated.

Thanks

PRO
Synthiam
#8   — Edited

The new button to create a plugin skill control is less than an inch below the button you pressed to create this question. :)

User-inserted image