Example: EZ-Script Executor
EZ-Script is the programming language used in EZ-Builder. The scripting language is similar to Basic and has many robot specific commands. The power of EZ-Script also allows controls to interact with each other using the ControlCommand(), which you may have already read about in this tutorial.
This part of the tutorial will demonstrate how to execute EZ-Script code within your plugin. An example of how this is useful is if your plugin provides configuration for the user to configure custom code for a specific action. If you look at DJ's Tic Tac Toe example, you will notice that the configuration dialog allows the user to create custom EZ-Script for Winning, Losing and Tie.
The namespace for all scripting methods is EZ_Builder.Scripting.
Simple Example This code example demonstrates how to run an EZ-Script piece of code that will speak a phrase out of the speaker when the button is pressed. You will need to add a Button to your form and assign the Click event for it to work.
public partial class MainForm : EZ_Builder.UCForms.FormPluginMaster {
EZ_Builder.Scripting.Executor _executor;
public MainForm()
: base() {
InitializeComponent();
_executor = new EZ_Builder.Scripting.Executor();
}
private void button1_Click(object sender, EventArgs e) {
_executor.StartScriptASync("Say(\"Hello, I am ez-script\")");
}
}
Example with Events There are many events that can be associated with the Executor, such as OnDone, OnError, etc.. This allows your program to accommodate behaviors. In this example, the Executor will display a message box when the script has completed executing.
public partial class MainForm : EZ_Builder.UCForms.FormPluginMaster {
EZ_Builder.Scripting.Executor _executor;
public MainForm()
: base() {
InitializeComponent();
_executor = new EZ_Builder.Scripting.Executor();
_executor.OnDone += _executor_OnDone;
}
private void button1_Click(object sender, EventArgs e) {
_executor.StartScriptASync("Say(\"Hello, I am ez-script\")");
}
void _executor_OnDone(string compilerName, TimeSpan timeTook) {
MessageBox.Show(string.Format("Script has completed and took {0} milliseconds", timeTook.TotalMilliseconds));
}
}
Starting A New Script When Another Is Running If the executor is currently running an ASync script in the background while you launch another, the first script will be cancelled and the most recent script will begin executing. Each instance of an Executor can run only one script. To run multiple scripts at the same time, use an Executor per script.
Inside the Executor The executor has many methods and events.
EZ_Builder.Scripting.Executor.ExecuteScriptSingleLine(string line); Executes only one line of EZ-Script and blocks until it has completed. This method returns the result of the single line of code. For example, if the code was a function to return the value of a servo (example GetServo(d0)), the value of the servo d0 will be returned.
EZ_Builder.Scripting.Executor.Resume(); There is an EZ-Script command to "Pause" the current running script. If the command is ever executed in the script, this will resume the execution.
EZ_Builder.Scripting.Executor.StartScriptASync(Command[] compiled); This executes the compiled Command Opcode array in the background. If you precompile the script into an array of Command Opcodes, this method can be used. The advantage to pre-compiling the source into Command Opcodes is that the script will execute faster because it will not need to be compiled each time. There is a compiler cache in the Executor, however. This means that if you run the same script twice that is not compiled, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StartScriptASync(string script); This method compiles the plain text EZ-Script and executes it in the background. There is a compiler cache in the Executor, however. This means that if you run the same script consecutive times, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StartScriptBlocking(Command[] compiled); Executes the compiled Command OpCode array on the current thread.
EZ_Builder.Scripting.Executor.StartScriptBlocking(string script); This method compiles the plain text EZ-Script and executes it on the current thread. There is a compiler cache in the Executor, however. This means that if you run the same script consecutive times, the last Opcode cache will be used.
EZ_Builder.Scripting.Executor.StopScript(); Stops the current ASync running EZ-Script on this Executor.
Events These events can be assigned to an Executor and will be raised at their appropriate function. The "CompilerName" parameter will include the optional compiler name that can be provided when the Executor class is initiated. In the above examples, the Executor class is created without any parameters. If a parameter was supplied, it would be the name of this compiler. If your program has many Executors that share these events, the CompilerName parameter will come in handy to identify what executor it originated from.
event OnCmdExecHandler(string compilerName, int lineNumber, string execTxt) Event is raised for each line that is executed in the script. This will dramatically slow the execution of the script, but is great for debugging.
event OnDoneHandler(string compilerName, TimeSpan timeTook) Event is raised when the script has completed.
event OnPausedHandler(string compilerName) Event is raised when the EZ-Script calls the Pause method. The Executor.Resume() function is necessary to continue, or StopScript().
event OnResumeHandler(string compilerName) Event is raised when the script is instructed to resume after a Pause.
event OnStartHandler(string compilerName) Event is raised when the script begins to execute.
Thanks for the quick response.
This what happens when you are working on robotics when its way past your bed time.
You miss the obvious
No problem - i get it

Sorry but can I ask you something why I didn't see the ARC library when I added visual studio even though I set up the C ++. DLL library and there's another way to execute it and send / receive console in out but I don't know how to do it with EZ_builder?Please follow the tutorial. It’s impossible to know why you’re plug-in isn’t showing up without asking you if you followed each step of the tutorial
. Reviewing your screenshots, it doesn’t appear as if any of the tutorial steps have been followed.
Hi i fixed it. thanks
Hello, I am trying the tutorial to get the robot to speak. I am using Visual studio. Currently, the sound is output from the pc instead of the robot. Is there a code I can attach so that the sound comes from the robot speakers instead of the pc?
Look in this tutorial for the step labeled "output audio from ezb". It’s lower down in the list. There’s instruction examples for either playing audio (ie mp3) or text to speech.
Error: the referenced component" EZ_builder,EZ_B" could not be found, DJ Sure i hope you can help me !

Joinny, you have to add the referencing by following the instructions in this tutorial. They are outlined with step by step to easily follow. Click add references, and browse to the appropriate files as directed in the tutorial. I can’t write anything clearer in response. The step to add references is incredibly clear but you’re skipping it.