Presentation is loading. Please wait.

Presentation is loading. Please wait.

EVENT DRIVEN SCRIPTING Andrew Williams. Robot Scripting Language  In the lab we looked at some very simple examples of Robot Scripting Language (RSL)

Similar presentations


Presentation on theme: "EVENT DRIVEN SCRIPTING Andrew Williams. Robot Scripting Language  In the lab we looked at some very simple examples of Robot Scripting Language (RSL)"— Presentation transcript:

1 EVENT DRIVEN SCRIPTING Andrew Williams

2 Robot Scripting Language  In the lab we looked at some very simple examples of Robot Scripting Language (RSL)  Today we will be looking at a bit of the theory  Specifically, we will be looking at event driven scripting  If you have ever done Visual Basic programming, you will have done event-driven programming/scripting

3 Events  What is an event?  A party  My birthday  A wedding  A football match  These are all events but not really what I mean  On the next slide I will give a definition that is more useful

4 What is an event?  An event is something that happens  This begs a question, “what sort of something”?  In the context of Robot Battle, some events are:  Initialisation – a robot has just been loaded  A robot gets hit by a missile  A robot bumps into something  A robot detects another robot  A robot is pinged by another robot

5 RSL scripting  When you are scripting in RSL, you are deciding how you want to handle the various events that can occur.  What do you want to do if you are hit by a missile?  What should you do if you detect an enemy robot?  What should you do if you detect a friendly robot?  What do you want to do if you bump into a wall?  Etc  But first of all, how does Robot Battle know what you want to do when you are (eg) pinged?

6 Event handlers  The answer to my question is that you must register an event handler  An event handler is a piece of a script that handles an event  You register your event handler to tell robot battle what you want to happen when the event occurs  Most of the time you will register your event handlers when your robot is first loaded up. ie in the initialization section

7 Million-dollar question  What is the initialization event handler called?

8 Init  All RSL scripts have an Init section  This defines various information that is general to the Robot  Registering the event handlers  Whether the gun rotates with the radar dish  Whether to handle certain events (eg wall collisions)  Init runs once when the robot is loaded  (You can force it to run again if you like)

9 Registering event handlers  Suppose we want to run a section called pinged each time our robot is pinged by another robot  What does “pinged” mean in this context?  The command is: regping(name_of_event_handler, priority)  So in our case, it is: regping(pinged, 1)  (We will come to priorities in a while)

10 Registering event handlers  Suppose our program looks like this: init { regping(pinged, 1) } pinged { # run away! } This is a comment

11 Registering event handlers  Our program registers the section we want to use to handle events  This section is called pinged  The section itself doesn’t actually do anything yet (it turns out that running away is tricky, as most of you saw last week)  It has a comment which tells us what we intend to do.  We will (presumably) work out the details later…

12 What if no events occur?  We presumably don’t want the robot to just sit there while no events are occurring – we saw the consequences of that last week  While robot battle is running, each robot in the arena gets a “turn” (it is all happening so quickly, it seems continuous, but it is actually a series of discrete events).  So how do we register an event handler for the “it’s your turn” event?

13 regcore(handler)  We register a handler for the “it’s your turn” event using regcore(…) init { regcore(myturn) # no priority - lowest } myturn { bodyleft(5) }

14 The “it’s my turn” handler  This event handler does not need a priority regcore(myturn)  It always runs with the lowest priority  Why do you think this is?  Answer: This handler deals with situations when nothing is going on. When something does happen, you want to deal with that first. You can go back to routine tasks once you’ve dealt with the important stuff.

15 What does this do? init { regcore(myturn) clipmoves(false) regcldwall(hitwall, 1) } myturn { ahead(100) } hitwall { bodyleft(90) }

16 Event handler priorities  1 is the highest priority  Suppose you register several event handlers  On a particular turn, several events might occur  A robot bumps into a wall  A robot gets hit by a missile  A robot gets pinged  The priority determines the order in which these events are handled  Generally, a lower priority handler can be interrupted by a higher priority handler


Download ppt "EVENT DRIVEN SCRIPTING Andrew Williams. Robot Scripting Language  In the lab we looked at some very simple examples of Robot Scripting Language (RSL)"

Similar presentations


Ads by Google