Differences

This shows you the differences between the selected revision and the current
version of the page.


wmebook:ch3 2007/12/06 12:24 wmebook:ch3 2008/07/21 07:49 current
Line 1: Line 1:
====== 3. First tour into the real WME realm ====== ====== 3. First tour into the real WME realm ======
-So we now about the tools and we learned the basics of scripting and it’s the time to see how this knowledge applies to the game development. Before we start this tour let’s first make a brief overview of the file types you’ll be using in wme (and I strongly recommend using this naming convention):+We've found out about the tools and we've learned the basics of scripting and it’s the time to see how this knowledge applies to the game development. Before we start this tour, let’s first make a brief overview of the file types you’ll be using in WME (and I strongly recommend using this naming convention):
***.script** – are the files which contains the actual program ***.script** – are the files which contains the actual program
Line 58: Line 58:
Now this may look to you as an overkill script for something as similar as checking if we were in some scene or not but trust me, there’s more to it than meets the eye. This is actually very clever script which counts with many different possibilities. It counts with the game which was newly started, it counts with a scene revisiting, it counts with the fact that you can have on enter special events. Remember those cinematic moments when you played an adventure, walked in some room only to see the bridge collapsing? You wouldn’t want to see it collapse every time you visit that scene. Once is enough for sure. Now this may look to you as an overkill script for something as similar as checking if we were in some scene or not but trust me, there’s more to it than meets the eye. This is actually very clever script which counts with many different possibilities. It counts with the game which was newly started, it counts with a scene revisiting, it counts with the fact that you can have on enter special events. Remember those cinematic moments when you played an adventure, walked in some room only to see the bridge collapsing? You wouldn’t want to see it collapse every time you visit that scene. Once is enough for sure.
-So now when we uncovered what’s going on in this script, it’s actually very simple. As there are thousands of different methods, I’ve decided to choose the non violent way how to present them when needed.+So now when we uncovered what’s going on in this script, it’s actually very simple. As there are thousands of different methods, I’ve decided to choose the non violent way how to present them when needed, although Max was very unhappy with me last time, I've consulted nonviolent approaches.
Let’s look at one example from the beginning of the script. Let’s look at one example from the beginning of the script.
Line 161: Line 161:
</code> </code>
-As we see we’ve scratched surface of two objects so far. Actor object and Region Entity object, which we referenced by keyword **this** and hid it through setting its attribute Active to false.+We’ve scratched surface of two objects so far. Actor object and Region Entity object, which we referenced by keyword **this** and hid it through setting its attribute **Active** to false.
Let me return back to the image we’ve seen at the beginning and look at this very image from a developers point of view. Let me return back to the image we’ve seen at the beginning and look at this very image from a developers point of view.
Line 266: Line 266:
</code> </code>
-**Never do this. It’ll halt your computer. Script takes over the whole processing power and the rest of the game never get control back. This way also Windows never gets control back which results is hung up computer.** So how to fix this?+**Never do this. It’ll halt your computer. Script takes over the whole processing power and the rest of the game never get control back. This way also Windows never gets control back which results in hung up computer.** So how to fix this?
<code script> <code script>
Line 277: Line 277:
} }
</code> </code>
 +
 +This daemon is correct (remember our previous chapter), because it hands over the control from the script. One millisecond is here only formally. The important fact is that you DO hand over the control.
 +
 +So enough theory and let’s make some daemon fun with the commands, we’ve just learned. Oh wait. We’d need one more command:
 +
 +**Game.Msg(text);** - although we’ve seen it before let’s recap that it displays an onscreen debug message. Very useful command.
 +
 +What we’re going to do is a funny little timed sequence, which occurs in our warehouse scene. The scenario is as follows. Player examines the door to discover that there’s a time bomb attached to it. If he can’t exit quickly enough, the Scene is reloaded (it’s the hardcore-adventure-fan-way how to tell the player, that he has died).
 +
 +First we’ll create the new script in the scr folder (from the empty template) and name it **bomb.script**.
 +
 +Tip: if you get more skilled, you can add the new files manually by creating a text file with a script extension created in the corresponding folder.
 +Then we modify the **door.script** so it’ll read the following:
 +
 +<code script>
 +#include "scripts\base.inc"
 +
 +on "LeftClick" 
 +{
 + Game.Interactive = false;    // We want our player to make more things at once and we don't want to be interrupted.
 + actor.GoToObject(this);
 + this.Active = false;  // We disable the door so the hotspot is not visible or active anymore.
 + actor.Talk("Oh no. There's a timed bomb attached to the door! I have to find an exit before it explodes.");
 + Scene.AttachScript("scenes\warehouse\scr\bomb.script");
 + Game.Interactive = true; // Allow player to play some more.
 +}
 +</code>
 +
 +I’ve hilighted the line which attaches our new script and thus starting the countdown.
 +Now let’s look at the **bomb.script** contents.
 +
 +<code script>
 +#include "scripts\base.inc"
 +
 +for (var timer=6;timer>-1;timer = timer -1)  // let's set up a loop which would go down from 6 to 0.
 +{
 + Game.Msg("Countdown: " + timer); //Let's display how much time do we have left.
 + Sleep(1000); // Sleep one second (and also hand the game over to other threads)
 +}
 +
 +Game.Interactive = false; //Death cutsene
 +actor.Talk("I've just died. Let's try again");
 +Game.ChangeScene("scenes\warehouse\warehouse.scene");
 +var door = Scene.GetNode("Door");
 +door.Active = true; // If we die, we need to return the door to its active state or we'll never discover the bomb again.
 +Game.Interactive = true;
 +</code>
 +
 +And the last change we’ll make is to the **exit.script**. If we found an exit in time, actor will be able to escape, but what if he arrives there in the nick of time and while talking his line, the time runs away and he dies? So let’s prevent this from happening by detaching the bomb script and letting him say something more reasonable.
 +
 +So the contents of the **exit.script** would look like this:
 +
 +<code script>
 +#include "scripts\base.inc"
 +
 +on "ActorEntry"
 +{
 + var door = Scene.GetNode("Door");
 + Game.Interactive = false;
 + if (door.Active)
 + {
 + actor.Talk("I don't want to return to my flat before I am sure I can't enter the warehouse!");
 + }
 + else
 + {
 + Scene.DetachScript("scenes\warehouse\scr\bomb.script");
 + actor.Talk("Phew. That was close");
 + Game.ChangeScene("scenes\room\room.scene");
 + }
 + Game.Interactive = true;
 +}
 +</code>
 +
 +Save everything and test our little scheme to see some more of the effects.
 +
 +On closing of this chapter I’ll introduce a little change to our scheme. This change is not necessary in our example, but it will be necessary in different case. For now we’re testing, if the entity region Door is Active for another decision. But what if we need to apply the similar logic to more than one scene? If we stand in different scene, we logically can’t use entity this way because it’s not anymore part of the current scene.
 +
 +So what we can do is using a global variable. Let’s make a change to our scripts then!
 +Last code listing for this script triplet is then (changes in bold):
 +
 +**bomb.script**
 +<code script>
 +#include "scripts\base.inc"
 +
 +for (var timer=6;timer>-1;timer = timer -1)  // let's set up a loop which would go down from 6 to 0.
 +{
 + Game.Msg("Countdown: " + timer); //Let's display how much time do we have left.
 + Sleep(1000); // Sleep one second (and also hand the game over to other threads)
 +}
 +
 +Game.Interactive = false; //Death cutsene
 +actor.Talk("I've just died. Let's try again");
 +var door = Scene.GetNode("Door");
 +door.Active = true; // If we die, we need to return the door to its active state or we'll never discover the bomb again.
 +global doorClicked = false;
 +Game.ChangeScene("scenes\warehouse\warehouse.scene");
 +Game.Interactive = true;
 +</code>
 +
 +**door.script**
 +<code script>
 +#include "scripts\base.inc"
 +
 +on "LeftClick" 
 +{
 + Game.Interactive = false;    // We want our player to make more things at once and we don't want to be interrupted.
 + global doorClicked = true;
 + actor.GoToObject(this);
 + this.Active = false;  // We disable the door so the hotspot is not visible or active anymore.
 + actor.Talk("Oh no. There's a timed bomb attached to the door! I have to find an exit before it explodes.");
 + Scene.AttachScript("scenes\warehouse\scr\bomb.script");
 + Game.Interactive = true; // Allow player to play some more.
 +}
 +</code>
 +
 +**exit.script**
 +<code script>
 +#include "scripts\base.inc"
 +
 +on "ActorEntry"
 +{
 + var door = Scene.GetNode("Door");
 + Game.Interactive = false;
 + global doorClicked;
 + if (!doorClicked)
 + {
 + actor.Talk("I don't want to return to my flat before I am sure I can't enter the warehouse!");
 + }
 + else
 + {
 + Scene.DetachScript("scenes\warehouse\scr\bomb.script");
 + actor.Talk("Phew. That was close");
 + Game.ChangeScene("scenes\room\room.scene");
 + }
 + Game.Interactive = true;
 +}
 +</code>
 +
 +We’ve seen in this chapter some neat tricks with the way how we can handle the game logic. We’ve also learned some of the important concepts for the tying scene to the code and we are able to use a couple of very basic commands and object methods. But for now we all the time used a lot of prebuilt demo code. Next chapter is all about starting the project from scratch. We’ll build upon this blank project until we create a little feature packed game. So stay tuned, we’re getting into it.
 
wmebook/ch3.1196940242.txt.gz · Last modified: 2007/12/06 12:24 by metamorphium
Recent changes RSS feed Creative Commons License Driven by DokuWiki