DimensioneX Change language Step 8


Home
Features
Play Online
Download
Forum
Tutorial
Documentation
Wiki
Support
Resources
Members
Gadgets
Contacts
Links






free screen-saver
Fantasy Screensavers and Desktop Backgrounds

 


DimensioneX on SourceForge.net

 

Interactivity

Now we have to add some degree of interactivity. Here are the issues we have to fix:

  1. The key #1 should unlock the door

  2. The surfer should return the scissors as soon as he gets a key

  3. The scissors should be able to un-seal the box

  4. By opening the box, the player should win the game

(Issues from 2 to 4 are solved in Step 8)

If we need to add interactivity, then an EVENTS section has to be added. So, please add it after the END_SETS keyword and before the END_WORLD keyword. Like this (copy+paste just the code in bold):

END_SETS

EVENTS

END_EVENTS

END_WORLD

Please note that the EVENTS section only delimits a text area. In this text area, you program in a very simple but yet classic programming language, called SmallBasic. SmallBasic is similar to VisualBasic or QBasic. You find all the necessary information in the Programmers' Reference.

This section is used to specify the behaviour of the game in relation to EVENTS. In order to fully understand what we will do now, you should go and read the section named "The DimensioneX EVENT model" in the Programmers' Reference. However, I suggest you can skip this by now and do it later.

Now we will program one event for each issue we have to solve, from the above numbered list. Let's go.

Unlocking the door

To unlock the door, you USE a key (say, key1) WITH the door (whose ID is w2) by using the USE WITH command. When you do this, a onUseWith event triggers. So, we specify what should be done in that case by using SmallBasic (insert code in the EVENTS section):

EVENTS
EVENT key1.onUseWith
ACTIONS
    If $TARGET=w2 AND w2.locked=1
	w2.locked=0 
	w2.open=1 
	Display "Click!"
    Else
    	Return false
    End_If

END_EVENTS

Here is a simple explanation of the above.

  • According to the DimensioneX event model, when the player uses the key1 with the door, the onUseWith event triggers associated to the key1 object, and the door (w2) is considered as the TARGET of the event.

  • Under the following conditions: (the key1 is used on the door w2) AND (w2 is locked) the block following the ACTIONS keyword will be executed:

  • The door unlocks, the door opens, a "Click!" message is displayed on the players' console.

Save the game, restart it and try it - it works and you can now enter the room. But you cannot yet open the box.

See the next step.

Previous Next

Note: If you do not like the USE WITH interface, you should know that you can design a custom command such as "Lock/Unlock", even render it as a graphic button. See the tutorial on Custom panels for this (but later, please, now continue this one until the finish)