4
« on: March 05, 2011, 08:28:49 PM »
Muchas gracias por tu respuesta y tu ayuda HelLRaiseR, la parte en concreto que no entiendo es porque realiza al final cambios en los scripts de la puerta, la bomba y la salida, por lo poco que he podido entender viene a decir algo así como que en esta escena valen los scripts que hemos ido creando a lo largo del tema pero que en otros casos no, ¿a que casos se refiere?¿o es que lo he entendido mal?, el fragmento es el siguiente:
"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
#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;
door.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.
}
exit.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;
}
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.