Mscape Help


Variables

What is a variable

There are times when you will need to access information in your mscape, for instance to make decisions on what happens when a particular event occurs. Some objects already contain information (known as properties) that you can access and use in this way. For example a Circle Region's EnteredCount tells you how many times a user has entered the region; so you could use this value to change which audio track is played to them the next time they enter it.

Sometimes however you will need to have access to information that is not stored in one of the existing objects, or you might want to store the state of an object at a particular time. For example you might want to know how many times the user went back to a particular region before they solved a puzzle. If they keep going back to the region after solving the puzzle the EnteredCount will keep going up, so you need to store this value separately.

To store this information Mscape needs to be specifically told it has to remember it and you do this by assigning the information to a variable. Think of a variable as a container for the information. Now, if you were stuck on a desert island and went on a foraging expedition you wouldn't be able to magically produce containers as and when you needed them - you would need to plan in advance and take them with you. The same is true of variables in Mscape. You need to decide what information you need to store and define the necessary variables in advance.

Variable types

To define a variable right-click on the State button and a menu appears:

state-1.gif

The question you might now ask yourself is "why so much choice"? Why not just one type of variable? To put it simply, computers have different types of containers depending on what you want to store in them. On your foraging expedition you wouldn't try and gather water in a basket, you would use a bottle. If you found some fruit it would go in the basket. The same concept applies when storing variables in Mscape. When you know the information you want to store is a number (e.g. coordinates, EnteredCounts etc.) you would create a Number variable. If it's a piece of text (e.g. a region's name) it would be stored in a Text variable and so on.

The reasons for this are twofold. The first is that the computer isn't good at knowing what kind of information you're giving it to store or how to handle it, so needs to be told. By telling it a variable is a number it then knows that, for example, if you add it to another number it should give you the sum.

The second is to ensure efficient use of the computer's physical memory. If you know a variable will only ever have two values you could store this as text ('on' or 'off', 'true' or 'false' etc.), or as a number ('0' or '1'). This is such a common requirement however that there is a specific type of variable - a boolean, or 'True False' in Mscape - designed to store it in the most efficient way possible. It also avoids the possibility for error, for example if you mistyped 'true' as 'treu'.

If you try and store information in the wrong kind of variable one of two things might happen: You will either get an error or the information will be converted to a different variable type. The latter is most likely to happen when you assign a number to a Text variable. This could become a problem if you then tried to add the variable to another number. Rather than giving you the sum of the two numbers the computer would treat them as text and combine them. For example where you might expect '2 + 1' to give a result of '3' the computer would give '21'.

This is a fairly simplistic overview of the more common variable types. State Lists are used to store lists of items (usually referred to as arrays) and the Group is an Mscape tool that allows you to save and load the values of variables to and from an external file.

Defining a variable

Once you have decided what type of variable you want to create right-click on State and select the type you want to add. With the variable selected, look at the properties below. It is a good idea to set the Name to something that meaningfully describes what the variable stores; and you may also find it useful to include what type of variable it is. You can also use this to set the starting Value of the variable.

Ready to
get started?

Download Mscape Suite Version 2.6 | 11 MB

Download Mscape Experimental

Experimental Beta Version 2.6 | 11 MB

Ask the Mscape Community

Forums