TWiki
> Main
>
EventScripts:AnIntroduction
Mediascape Scripting Language: an introduction
What is an event script?
An event script is a little piece of programming that is associated with an event and that is followed when that event happens. When an event happens the script is triggered and reacts to that particular event.
Think of it as being like hospital staff. When an event happens like ‘baby born’ that event triggers a number of people into action who are specially skilled to deal with that event.
In a mediascape the events are not quite as dramatic and are dictated by the nature of mediascape, so that events are such things as ‘the user has entered a region’, ‘the user has pressed button A on the device while in region 23’, etc.
If you are familiar with Flash...
Some people involved in multimedia may already have familiarity with a number of different packages and systems. If you have some familiarity with Flash and ActionScript (the programming language used in Flash) then this could be useful in terms of understanding the behaviour of event scripts in the mscape maker.
In Flash, much can be achieved through the act of dragging and dropping assets onto the stage and coupling various behaviours to them. However once you move into the world of ActionScript many other things become possible, it becomes easier to do things that took time with the drag-and-drop interaction and it becomes possible to do things that you couldn’t do before.
The situation is similar with the mscape maker, you can do quite a bit with the drag-and-drop interface but you can do more with the scripting abilities.
Writing event scripts is programming
The way that you write event scripts in the mscape maker is based on parts of a programming language called C# (pronounced ‘sea sharp’). If you are a programmer and you have used C# you will see things that you are familiar with. If you have programming experience in languages like C++, JavaScript or Flash ActionScript then some aspects of it will be familiar.
However, if you are not a programmer then do not despair, you can pick it up fairly quickly and you can achieve quite advanced things without having to do lots of programming.
Things you can do with event scripts
Event scripts are a useful way of doing more complex things with what you have got. You can make your mediascape do things like this:
Link two sounds to a region, play one sound the first time someone enters a region and then only play the second sound whenever they re-enter that region.
Have a game where there is a region containing sound and images of a lion, and the user can wander around and then select a point in the space they are in by clicking a button on the screen to say ‘put the lion region at the point where I am standing’.
Play a sound that asks the user a questions and they can answer by clicking on ‘yes’ or ‘no’ buttons on the screen. The mediascape can then adjust itself depending on their answer.
Have a go of some of the mediascapes available on the mscape website to experience more of the possibilities.
The basics of event scripts
Event scripts are about doing things in response to events. So the basic model is that you can say ‘when this particular event occurs I want you to do this action’. Simple enough, but what does that look like when it is translated in to the language of event scripts. Let's build up the structure bit by bit.
I want to say 'if this particular event has happened then do this thing and do this thing as well'. To express this 'if-then' in script I would write the following:
if (this particular event has happened)
{
Do this thing;
Do this thing as well;
}
|
- NOTE
- The list of things to do is enclosed with 'pointy brackets' (or 'braces' or whatever you want to call them).
- Each thing to be done instruction is ended with a semi-colon.
- There is NO semi colon after the 'if (this particular event has happened)'. You can think of the semi-colon as behaving like a full-stop in writing.
- The condition of the 'if' part is enclosed in brackets.
If we wanted to play a fanfare of trumpets the fourth time the user entered a region around an old ruined castle then we would want a script that looked like this:
if (it's the fourth time that the user has entered the region be the casle gate)
{
Play the trumpet fanfare;
}
|
Of course this combination of script and chatty sentences won't work. To make it work we actually would write:
if (castle_gate.EnteredCount == 4)
{
fanfare.Play();
fanfare.Volume = 100;
}
|
Where 'castle_gate' is the region we have defined in the right place on the map and 'fanfare' is the audio file of trumpets that we have imported into the mediascape.
- NOTE
- When we set something we use one equals sign, so we use '=' when setting the volume. (In effect 'make this equal to').
- When we are doing an 'if' and want to test if two things are equal we use two equals signs; '=='. (In effect 'is this equal to').
The underlying model in scripts in the mscape maker is that you create things and these things have actions associated with them. You can call up these actions by addressing the object and telling it the action you want it to do.
For a good comparison imagine being in the house of the future where everything is intelligent and can react to your voice. You could not just shout ‘switch on’ when you came into a room, you would have to say what you wanted to switch on ‘Lights; switch on!’ or ‘TV; switch on!’. Other things would have other actions that you could call upon; ‘Door; open’ or ‘Curtains; close’. Certain objects would only have certain actions, so you couldn’t say ‘Curtains; switch on’ for example. And imagine if things were so advanced that CDs could play themselves, so if you wanted to listen to the Scissor Sisters latest you wouldn’t talk to the CD player you’d just say ‘ScissorSisters; play!’
Now you can see similar things in the portion of script above. We have two things; we have the region around the castle; ‘castle_gate’ and the audio object ‘fanfare’ which is a recording of a trumpet fanfare. When we want to find out about the number of times the user has entered the region we ask for that property of the region; ‘castle_gate.EnteredCount’. When we want to do things to the audio we address it directly by name and then tell it what we want of it, so ‘fanfare.Volume = 100’ sets its volume to 100 and; ‘fanfare.Play()’ makes it play.
Play has brackets and Volume doesn’t because Volume is a property of the fanfare whereas Play is an action that fanfare can carry out. Properties are like nouns and actions are like verbs.
Finding out more
Help pages
In the help pages on the mscape maker and the help pages on the website there is more technical documentation about the possibilities of the different script objects. For example you could find out more about all the things you can do with audio objects; you can do far more than just play them.
Example mediascapes
If you have downloaded a mediascape from the mscape website you can run it on your mobile device, alternatively you can open it up in the mscape maker and examine how the designer has put it together. One of the things you can look at is the event script window in the bottom right corner of the window. This shows the event (written in the tab) and the script that is followed when the event happens. You can click on different objects in the mediascape to look at the script associated with them. As well as the objects on the map in the main part of the screen all the things in the left hand bar are objects and they too can have scripts. Even the top level object of the mediascape has two events that can have script in them.