<< Click to Display Table of Contents >> Navigation: Advanced Features > Scripting > Other Scripting Langauges > C# Scripting |
Sample Code
//Vertex C# Sample Code //Pass input parameter to variable var input = input1;
for(int i = 0; i < 10; i++) { //Call a Vertex Script from C# script code Script.Run("Log Hello C# " + i); System.Threading.Thread.Sleep(500); }
//Get a return value from Vertex Scripting var r = Script.Run("Return SystemsManager.GetStatus");
//Return a value to Vertex Scripting return "Return from C#"; |
C# Engine interacts with VERTEX Script commands.
Script.Run lets you interact from C# with VERTEX scripting.
Script.Run allows the passing of multi line scripts.
previous code:
Script.Run("Playback1.Active.Value = true");
Script.Run("Playback2.Active.Value = true");
Script.Run("Playback3.Active.Value = false");
Script.Run("Playback4.Active.Value = false");
new code:
Script.Run(@"Playback1.Active.Value = true
Playback2.Active.Value = true
Playback3.Active.Value = false
Playback4.Active.Value = false");
The "@" (verbatim string literal) is important for adding multilines inside String-Literals. Alternatively you can combine them instead of the "@" with "\n" .
Script.Run has now got its signature changed allowing for optional parameters:
public static object Run(string script, params object[] parameters)
previous code:
Script.Run("Playback1.FadetoCuePlay " + newMessage.ToString());
new code:
Script.Run("Playback1.FadetoCuePlay", newMessage);
Currently, this just saves the time to concatenate the strings manually. In the future we'll be able to optimize these calls efficiently.
However, his does not work with multiline scripts.
The use of Script.Log command is simpler and more efficient than before:
previous code:
Script.Run("Log Status: "+message);
new code:
Script.Log("Status: "+message);
Omit the "Log" before "Status".
previous code:
Script.Run("Var_MyVal.value = My Value");
new code:
Script.SetVariable("Var_MyVal", "My Value");
object Script.GetVariable(name)
T GetVariable<T>(string name, T defaultResult = default)
previous code:
String MyValreturn = Script.Run("return Var_MyReturnVal.Value").ToString();
new code:
var MyValreturn = Script.GetVariable<string>("Var_MyReturnVal");
The generic variant takes over the necessary value conversion (by internal converters).
This is another function helping to avoid extensive concatenations of Script.Run strings as well as avoiding IfExecute from within C#.
It is just way more efficient using C#'s native logic:
previous code:
Script.Run("IfExecute Var_MyVal.Value, Device1.SendMessage "+message);
new code:
if(Script.GetVariable<bool>("Var_MyVal")) Script.Run("Device1.SendMessage", message");