Using Values in Ogmo Editor
by Matt Thorson
Contents
- What Are Values?
- Level Values
- Object Values
- Value Output
1. What Are Values?
In Ogmo Editor, a "Value" is like a variable in programming. If a class in an object oriented language has an instance variable "x", each instance of that class can hold its own value for x.
Similarily, objects in Ogmo Editor can have values. For example, a treasure chest object could have a "coins" value, which holds an integer from 0 to 20. Then for every instance of the treasure chest you place on your levels, you can define a different integer from 0 to 20 as the amount of coins in that chest. This number will then be output into your level file as an attribute of that treasure chest tag when the level is saved.
In addition, levels themselves can have values. A level could have a "title" value, holding a string which represents the name of the level. Or perhaps a level has a "difficulty" value - an integer representation of the difficulty of a stage.
2. Level Values
Let's start by opening up the Ogmo Editor example project. The example project is copied to your hard drive when you install the editor, in its application folder. On Windows this defaults to "Program Files/OgmoEditor". Open the "exampleProject.oep" file in the editor.
Click the title bar of the "Level Settings" window and drag it up. Inside you'll see that you can change the level's width and height, but also a value called "title". This is a level value defined in the project file. Let's open up the project file in a text editor and see how this is done.
<project>
<name>Ogmo Editor Example Project</name>
<settings>
<defaultWidth>640</defaultWidth>
<defaultHeight>480</defaultHeight>
<minWidth>320</minWidth>
<minHeight>240</minHeight>
<maxWidth>960</maxWidth>
<maxHeight>720</maxHeight>
<workingDirectory>gfx</workingDirectory>
</settings>
<values>
<string name="title" default="new level" maxChars="12" />
</values>
<tilesets>
<tileset name="bricks" image="tiles_bricks.png" tileWidth="16" tileHeight="16" />
<tileset name="grass" image="tiles_grass.png" tileWidth="16" tileHeight="16" />
</tilesets>
<objects>
<object name="ogmo" image="ogmo.png" width="16" height="16" limit="1"/>
<object name="chest" image="chest.png" width="16" height="16">
<values>
<integer name="coins" min="0" max="20" default="2" />
</values>
</object>
<object name="moving_platform" image="moving_platform.png" width="16" height="16" resizableX="true" resizableY="true" tile="true">
<values>
<number name="speed" min="0.1" max="5" default="1" />
</values>
<nodes drawObject="true" limit="1"/>
</object>
<folder name="dangers" image="spikes_ground.png">
<object name="spikes_ground" image="spikes_ground.png" tile="true" width="16" height="16" resizableX="true" />
<object name="spikes_ceiling" image="spikes_ceiling.png" tile="true" width="16" height="16" resizableX="true" />
<object name="spikes_left" image="spikes_left.png" tile="true" width="16" height="16" resizableY="true" />
<object name="spikes_right" image="spikes_right.png" tile="true" width="16" height="16" resizableY="true" />
</folder>
</objects>
<layers>
<tiles name="tiles_bg" gridSize="16" drawGridSize="64" exportTileIDs="true"/>
<grid name="floors" gridSize="16" exportAsObjects="true" />
<objects name="objects" gridSize="16" drawGridSize="32" />
<tiles name="tiles_floors" gridSize="16" drawGridSize="64" exportTileIDs="true"/>
</layers>
</project>
There's a lot here so I've highlighted the area of interest. In the <project> tag we simply have a <values> tag, which holds all of our values. Right now we just have a single <string> value. We have the default string defined as "new level", and we have maxChars (the maximum length in characters) of the string set to 12.
Now let's try adding an <integer> value.
<values>
<string name="title" default="new level" maxChars="12" />
<integer name="difficulty" default="1" min="1" max="5" />
</values>
Now our level will have a "difficulty" value. It will be an integer with a default of 1. The range of possible values will be 1-5. Open up the project and see your new value in action! It is worth noting that <integer> values can also be negative if you set min to a negative number. In addition, both the min and max attributes are optional, if not provided the value will have no min/max.
Now let's pretend that in our game, we want each level to start with a message box with some text, maybe storyline or tutorial text. We want to define this text in the editor, but it's going to be a lot longer that our "title" string. For this we can use the <text> value. <text> values are exactly like <string> values, except the entry box for them in the editor is bigger. Let's add one, then load the project back up and check out how it works.
<values>
<string name="title" default="new level" maxChars="12" />
<integer name="difficulty" default="1" min="1" max="5" />
<text name="message" default="Hello world!" maxChars="120" />
</values>
You'll see that the input field for a <text> value is much larger than for a <string> value. There are two more value types. <boolean> values can be either true or false, and appear as checkboxes in the editor. <number> values are exactly like <integer> values except they allow floating point values (eg. "3.6", "-2.4"). Here are some examples of how to define them:
<values>
<string name="title" default="new level" maxChars="12" />
<integer name="difficulty" default="1" min="1" max="5" />
<text name="message" default="Hello world!" maxChars="120" />
<boolean name="lights" default="true" />
<number name="gravity" default="1.8" min="-1.2" max="5.2" />
</values>
3. Object Values
Now that we know all the value types and how to define them, we can attach them to objects as well! Look in the project file again, but this time inside a certain project tag (highlighted below).
<project>
<name>Ogmo Editor Example Project</name>
<settings>
<defaultWidth>640</defaultWidth>
<defaultHeight>480</defaultHeight>
<minWidth>320</minWidth>
<minHeight>240</minHeight>
<maxWidth>960</maxWidth>
<maxHeight>720</maxHeight>
<workingDirectory>gfx</workingDirectory>
</settings>
<values>
<string name="title" default="new level" maxChars="12" />
<integer name="difficulty" default="1" min="1" max="5" />
<text name="message" default="Hello world!" maxChars="120" />
<boolean name="lights" default="true" />
<number name="gravity" default="1.8" min="-1.2" max="5.2" />
</values>
<tilesets>
<tileset name="bricks" image="tiles_bricks.png" tileWidth="16" tileHeight="16" />
<tileset name="grass" image="tiles_grass.png" tileWidth="16" tileHeight="16" />
</tilesets>
<objects>
<object name="ogmo" image="ogmo.png" width="16" height="16" limit="1"/>
<object name="chest" image="chest.png" width="16" height="16">
<values>
<integer name="coins" min="0" max="20" default="2" />
</values>
</object>
<object name="moving_platform" image="moving_platform.png" width="16" height="16" resizableX="true" resizableY="true" tile="true">
<values>
<number name="speed" min="0.1" max="5" default="1" />
</values>
<nodes drawObject="true" limit="1"/>
</object>
<folder name="dangers" image="spikes_ground.png">
<object name="spikes_ground" image="spikes_ground.png" tile="true" width="16" height="16" resizableX="true" />
<object name="spikes_ceiling" image="spikes_ceiling.png" tile="true" width="16" height="16" resizableX="true" />
<object name="spikes_left" image="spikes_left.png" tile="true" width="16" height="16" resizableY="true" />
<object name="spikes_right" image="spikes_right.png" tile="true" width="16" height="16" resizableY="true" />
</folder>
</objects>
<layers>
<tiles name="tiles_bg" gridSize="16" drawGridSize="64" exportTileIDs="true"/>
<grid name="floors" gridSize="16" exportAsObjects="true" />
<objects name="objects" gridSize="16" drawGridSize="32" />
<tiles name="tiles_floors" gridSize="16" drawGridSize="64" exportTileIDs="true"/>
</layers>
</project>
This is our tresure chest object which can hold any amount of coins from 0 to 20. Note that the <object> tag holds a <values> tag which then holds all the object's values.
Open the project in the editor, and go to the "objects" layer. Select the "chest" object (second from the left) and place a couple on the stage. Now switch to the "Select" tool and select one of them.
In the "Selection" window, you can see that we can edit the value for "coins" for this instance of chest. If we change it then select a different instance, the value is different. We can choose a different value for "coins" for each instance of chest individually.
Objects can have any amount of values, and they can be of any of the same types described in the level values section.
4. Value Output
Values are output as attributes of the tags they reside in. So for level values, they will be attributes of the root <level> tag. For object values, they will be attributes of the <object> tags. Below is a simple level file from the example project with the value attributes highlighted.
<level title="The Best Level">
<width>640</width>
<height>480</height>
<floors>
<rect x="176" y="160" w="128" h="96"/>
<rect x="448" y="224" w="80" h="64"/>
</floors>
<objects>
<ogmo x="192" y="144"/>
<chest x="256" y="144" coins="1"/>
<chest x="480" y="208" coins="7"/>
</objects>
</level>