Step 7 - Adding Special Functions
Special functions can (among other things) display a message, change the player sprite, jump to a new map, transport the player to a new location, change the map (by copying rectangles from other places on the map), create a new sprite instance, or simply raise an event to be handled by script. Each function corresponds to a rectangle drawn on the map in the map editor. Then the parameters of the function can be defined on the special functions tab of the map editing dialog. We will be defining the parameters of 4 functions we created in step 3. They will all be functions that alter the map in terms of the other two defined functions.
Open up the Map Editing dialog (View; Maps) and select TutorialMap. Switch to the Special Functions tab in the lower portion of the dialog and you will see all the special functions defined on this map listed along the left side. The parameters of a function are further split into two tabs. Action parameters determine what triggers the function and how its triggering interacts with the inventory. Effect determines what the function does when its triggered.
Before setting the parameters for our special functions you will need to know the coordinates of the closed passage (the tile coordinates of the top left corner). If you do not know these, go back to the Layers tab, click on the Main layer and click the Edit button. Locate the top left tile of the obstruction in the passageway and put the mouse over it. Note the coordinates displayed in the upper-left corner (then close the editor). These are the coordinates required for defining our special functions. In my case the coordinates are 38,7. If you had to go to the layers tab to get these coordinates, now return to the Special Functions tab.
Select the OpenSesame1 function. In the Action Parameters tab check the "Initial touch only" and "Uses inventory item" boxes. Select "SesameStaff" as the item used and leave "How many" at 1 (only 1 SesameStaff is required). Leaving the "Remove item(s) on use" checkbox unchecked will ensure that the item can't be used up. Click the update button before continuing. You could delay the update until you're done with the Effect tab, but why risk it? :)
In the Effect tab select "Alter map" for the function. Under "Copy tiles from function" select "Open". This will copy the tiles underneath the rectangle for the "Open" function to the specified coordinates. In the "X" and "Y" fields, enter the coordinates noted above (X=38 and Y=7 in my case). Don't touch the "Pick coordinates" box. That field is not a stored parameter, but rather a control you can use to set the coordinates based on the two functions involved. For instance, if you were to select "Match top-lefts", the coordinates would be automatically entered such that the top left corner of the "Open" rectangle would be copied to the top left corner of the "OpenSesame1" rectangle. This isn't useful in this case because the location of the "OpenSesame1" function is irrelavent to the area of the map we want to change (it's nearby, but no corner matches the same corner of the area we want to change). Click the "Update" button to save the new parameters for this function. Switch back to the Action Parameters tab and verify that the parameters are all still correct for OpenSesame1.
Now select the OpenSesame2 function. All the parameters on the Action Parameters and the Effect tabs should be the same because this function should do the same thing as OpenSesame1. Make sure they are and hit Update.
The CloseSesame functions will be a bit different from the OpenSesame functions. Select each CloseSesame function and set the parameters as follows:
The Open and Closed functions don't need to be defined at all because they are not going to be used as functions. They are only used to define the rectangles that are copied by other functions.
That's everything! The game is completely playable now. Save the map and save the project. Now try playing it by selecting "Play" from the File menu on the main project window. The arrow keys control the motion of the ship. To change this you can select "Controller Configuration" from the view menu.
This concludes step 7 of the GameDev tutorial - Adding Special Functions.
Return to the main tutorial page.
Jump to the next step in the tutorial.