Mscape Help


How To: Use the user's history when triggering media

One of the ways to enrich a user's experience of a mediascape is to make the behaviour of the mediascape dependent on what the user has already done. For example, imagine playing one piece of audio when the user enters a region for the first time and a different piece of audio when the user returns to that region. In the mscape platform, such behaviour can be simply enabled through a combination of basic scripting and built-in properties. This tutorial will show you how.

Let's begin by creating a new mediascape, importing some media, adding a map and creating a region. Or, to save time, just download this mediascape and open it in the mscape maker. You should see something like this:

HowToUseHistoryStarter.gif

As you can see, this simple mediascape has a single region, named enteredBefore, and two images - BritishFlag and beach. We will return to audio shortly.

Now, click on the enteredBefore region in the Place Editor panel and type the following code into the OnEnter event handler in the Script Window:

if (enteredBefore.EnteredCount == 1) 
{
   beach.Show();
}
else {
   BritishFlag.Show();
}

Try running this mediascape in the tester. First, click inside the enteredBefore region - you should see a picture of a beach appear in the top left panel. Now click outside the region and back in again. This time you should see two islanders and the British flag. What do you think would happen if you left the region and entered it again? Try it and see!

This bit of script works by testing the valus of a built-in property when the region is entered. Go back to the mscape maker, select the enteredBefore region and look at the property panel in the lower left corner. Note that you may need to resize or scroll this panel to see all the properties.

regionProperties.gif

Many of these properties will be self-explanatory. We want to focus on the first property in the Status section - EnteredCount. This will be grayed out and you will not be able to change its value, unlike some other properties. That's because EnteredCount is a run-time property whose value is filled in automatically by the player while the mediascape is being used. You have probably worked out by now that this particular property counts the number of times the user has entered that region since loading the mediascape. Hence the logic we added to the region's OnEnter event handler.

So that's the basics done. We can test whether the user has been to this region before and display different images accordingly. You might also see how you could use a similar test to see whether the user has already visited a different region, or to show different images on each of the first five visits to a region.

As you might expect, there are other properties that you can test, both for regions and for other script objects. Let's illustrate this by returning to think about audio. We could use the same piece of logic just illustrated to play different pieces of audio when the user enters the region for the first time and on subsequent occasions. However, we might also want to ensure that the user hears all of the first piece of audio before she hears the second audio, even if she leaves and re-enters the region before that first audio has finished playing. We can satisfy those two requirements by slightly changing the event handler script to read:

if (ukintro.Played == false) 
{
   ukintro.Play();
}
else 
{
   uka3.Play();
}

The crucial change is that now we test the Played property of the ukintro audio rather than the EnteredCount of the enteredBefore region. You can download a mediascape including this script fragment here. You will find the new script in the OnEnter event for the new region heardBefore. Try running the mediascape in the tester and hear what happens as you move in and out of the region. By the way, for those of you wondering about the possibility of playing the ukintro audio multiple times if you re-enter the region before it has finished, don't worry. Calling the Play method on an audio that is already playing has no effect.

So that's it for this tutorial. Use the right-click Help menu on other script objects to find out what other properties you can use in this way. You might also want to think how user-defined state variables can be used in such tests ... but that is a topic for another article..

Ready to
get started?

Download Mscape Suite Version 2.1 | 10.5 MB

Ask the Mscape Community

Forums