Asked — Edited
Resolved Resolved by Rich!

How Do I Make A Script?

hi i managed to find the sonar and got the sound to. i have the rgb,so how do i wright all this in a script. what i want is that the sonar turn whit sound and when he spot an object. the rgb flach red whit sound danger danger danger.



Upgrade to ARC Pro

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!



nope that doesn work?

United Kingdom

Nomad, I suggest you check out the EZ-Script Tutorial. It covers the basics.

Once you have understood the EZ-Script Tutorial you will have a better understanding of what a script is, the available commands, which commands are required for the task you have described and how to easily create the script without much typing at all.

In addition to the EZ-Script Tutorial there is also the EZ-Script Manual which I recommend reading through so that you can understand which commands do what, how they work and the correct syntax.



thank you for the link.


@Nomad ... I don't think you need our help anymore to find the tutorials how to do all this stuff, do you?


OK nomad, what you'll need to do is make a script which does the following.

  1. It has to track the position of the sonar servo. This can be done by:
$sonar=GetServo(d3)#sets the sonar variable to the servo position
  1. You need to get the sonar scanning. Here's what you do for a sonar script:
#start scaning
servo(d3, + 1) #Takes the current servo position and adds 1 position to it.

  1. The detection part. This either moves your rgb bar and turns it red or loops around.
If (GetPing(d5, d6) < 20)  #set to your min distance, this is what triggers the warning
Servo(d9, $sonar) #this moves the light bar to the same position as the sonar
sayezb("Danger, Danger, Danger") #your audible warning
#Light code goes here

Goto(loop)# this loops the warning code

Any problems please tell me and ill fix it(anyone).

United Kingdom

Techno, just curious as to what the + 1 is in the code.

servo(d3, + 1)

Have I missed a function in EZ-Script?


That was meant as take the current position and add one. Should be $sonar +1.

Final code V1

#Default light code goes here, AKA blue or safe color

#Default servo positions
Servo(d3, 1)
Servo(d9, 90)

#Set this to the sonar servo port.

#start scaning

#Set your max position here
If ($sonar = 180)
servo(d3, 1)
Elseif ($sonar <180)
servo(d3, $sonar + 1)

#Set distance min here
If (GetPing(d5, d6) < 20)
Servo(d9, $sonar)
sayezb("Danger, Danger, Danger")
#Light code goes here

United Kingdom


$sonar=GetServo(d3)#sets the sonar variable to the servo position

before or after the :loop?

What happens when it hits position 180?

What's wrong with ServoUp() or ServoDown()?


Edit: Posted before previous post was seen.

United Kingdom

The problem with that one is it'll move the servo up to position 180 then jump back to position 1. Sonar swings from side to side rather than moving from one to the other then jumping back again.

How would you go about making it move in increments from 1 to 180 then 180 back down to 1? Hint: I just posted a similar script

You may also want to add some small sleeps in there since EZ-Script can carry out thousands of commands per second.

Personally speaking, and this is what I did in PingRoam, increments of 1 may be too small. With PingRoam I had 3 positions which worked well, it could have been smoother with smaller increments than 25 steps per movement but I wouldn't go as low as 1.


Just a sample for Nomad so he can understand the basics. I learn better from example.



visuel is best to learn.for i can change the values here.see pic

User-inserted image

this is what i use sofar.

thank you very much

United Kingdom

Nomad, you will need to know what the commands do too. Using code from other people will only get you so far.

If you want to learn from code which works I would advise reading through this topic.

In fact, read through any of my topics where I've posted scripts, I always explain each step and comment the code fully so that it's easy to follow, easy to understand and easy to change. Click here for the list of my topics.


rich i have to start somewhere.


United Kingdom

Open, Examples, EZ-Script Examples is also a good place to start. Open, Examples, EZ-Script Functions Syntax is another good place to try.

All commands are covered by at least one Example Project in the EZ-Script Functions Syntax folder in ARC. The EZ-Script Examples folder has some good examples in too from a Security Guard to controlling a 7 segment display and many more.

But it all means nothing if you don't learn what the commands do and how they work.

Check out an example. Read the script. Look up the commands used in the EZ-Script Manual. Once you get some understanding of that example move on to another one.