Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Tutorial - Haveing multi entrence and exits to and from your zones.  (Read 2638 times)

0 Members and 1 Guest are viewing this topic.

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 352
    • View Profile
    • Jyujinkai's WME Development Blog

Jyujinkai's Continuing Tutorials for Nubs and the Programming Impaired (like me)
(sorry but i can only properly support windows)

Haveing multi entrence and exits to and from your zones.

Summery

The default scene files that come with WME have set start positions for the actor as soon as the room loads. For most cases this is fine. Though in some cases you will find that you need to have different start locations in the same room.

The prime example of this is if you have a large main room, with a number of exits all leading to different rooms. If you enter the main room from one of these doorways you want to have the actor appear near the doorway.

Lets have a quick look at the default scenes_int.script file that come with WME

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. // here comes the stuff which initializes the scene
  4.  
  5. actor.SkipTo(400, 400);
  6. actor.Direction = DI_DOWN;
  7. actor.Active = true;
  8.  
  9.  
  10. ////////////////////////////////////////////////////////////////////////////////
  11. // scene state
  12. global StateRoom;
  13.  
  14.  
  15. // default values
  16. if(StateRoom==null)
  17. {
  18.   StateRoom.Visited = false;
  19.   // add scene states here
  20. }
  21.  
  22.  
  23.  
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // setup scene according to state variables
  26.  
  27.  
  28.  
  29. ////////////////////////////////////////////////////////////////////////////////
  30. if(!StateRoom.Visited)
  31. {
  32.   StateRoom.Visited = true;
  33.  
  34.   // this is our first visit in this scene...
  35. }

Ok the bit we are interested in is

Code: WME Script
  1. actor.SkipTo(400, 400);
  2. actor.Direction = DI_DOWN;

What this means is as the scene is loaded it will take the actor and "SkipTo" (place) it at the cords 400, 400 and also point the actor in the DI_DOWN (Direction Down). So. by simply editing these values you can change the start position of you actor whenever the scene loads.

OK... The Good Stuff

Here is a layout of our scene


We have a long hallway and a room at each end. If you exit the kitchen, when the hallway room loads you want the actor position to look like he just left the kitchen, same for the ballroom... so depending on witch room you exit you want a different position for your actor in the hallway scene.

Ok..... for easy sake i will use the initial scene transition code from the tutorials. This is strait from the manual tutorials that you all have done. It is the bit that uses a entity with a actor position code in it and a script to move the actor to the entity and then change scenes on a left click.

So.... the Kitchen and the ballroom both have this code on an entity witch you left click to enter the ballroom.

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   actor.GoToObject(this);
  4.   Game.ChangeScene("scenes\ballroom\ballroom.scene");
  5. }

Ok... enough background....

Passing a global variable between scenes

So lest do this.... The way it will work is that we will define a variable, witch is passed from one scene to the other. witch can then be tested in the hallway scene, thus enabling the hallway to identify  witch scene the variable came from. And this is how you do it.

1) Change the transition code in the kitchen entity script from the default (written above) to this new code.

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   global ExitSceneGV = "kitchen2hallway";
  4.   actor.GoToObject(this);
  5.   Game.ChangeScene("scenes\ballroom\ballroom.scene");
  6. }

Pause and understand what has happened

All we have done is added a single line of code "global ExitSceneGV = "kitchen2hallway";" to the transition script. All it is doing is defining a global Variable for our project called ExitSceneGV (Exit Scene Global Variable). A Global variable is a variable that is not bound to any location it can be accessed from anywhere. As in acessed in one scene, and then another scene.

You can use this same Global variable for your entire project for your simple scene transition needs, so name it easy to spell and unique.

Ok.. so we have our global variable "ExitSceneGV " and it contains the information "kitchen2hallway". So lets see how to use it!

1) Load up your ballroom scene's scene_int.script. It will look like the code at the top of this tutorial.

2) Find and delete these lines

Code: WME Script
  1. actor.SkipTo(400, 400);
  2. actor.Direction = DI_DOWN;

3) Replace them with these lines.

Code: WME Script
  1. global ExitSceneGV ;
  2. //Enter from Kitchen
  3. if(Game.PrevScene=="kitchen")
  4. {
  5.   if(ExitSceneGV == "kitchen2hallway")
  6.   {
  7.         actor.SkipTo(400, 400);
  8.         actor.Direction = DI_DOWN;
  9.   }
  10. }

Pause and understand what has happened

The scene initialisation script is loading the scene as it dose so it loads the global variable, it then uses a TEST, with the IF loop. It breaks down like this.

1) First it dose a test to see if the previous scene was the kitchen scene
2) It then dose a test to see if the global variable it has loaded is the correct one. (the variable was set as you left the kitchen zone)
3) If those tests are true.. then it will execute the actor placement code. Witch is

Code: WME Script
  1. actor.SkipTo(400, 400);
  2.         actor.Direction = DI_DOWN;


That is it you have tested the variable and done what is needed... the next step is to do the same things for the ballroom.... the code looks like this

Ballroom exit scene script

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   global ExitSceneGV = "ballroom2hallway";
  4.   actor.GoToObject(this);
  5.   Game.ChangeScene("scenes\ballroom\ballroom.scene");
  6. }

And the scene_init.script for the hallway is now

Code: WME Script
  1. global ExitSceneGV ;
  2. //Enter from Kitchen
  3. if(Game.PrevScene=="kitchen")
  4. {
  5.   if(ExitSceneGV == "kitchen2hallway")
  6.   {
  7.         actor.SkipTo(400, 400);
  8.         actor.Direction = DI_DOWN;
  9.   }
  10. }
  11. //Enter from Hallway
  12. if(Game.PrevScene=="ballroom")
  13. {
  14.   if(ExitSceneGV == "ballroom2hallway")
  15.   {
  16.         actor.SkipTo(400, 400);
  17.         actor.Direction = DI_DOWN;
  18.   }
  19. }


That is it your done!!! Simple make sure the SkipTo is set to diffrent values and the actor will apear on diffrent sides of the room!!!!!!





Additional

If you have a U shaped hall witch exits into a single room but on different sides you need to slightly modify this code.


So in this one you have 2 exits from another hallway room that have different actor positions in the ballroom. Do all the transitions things the  same as before.. so just trigger your scene change and at the same time and define the global variable. (remember use the same variable for your entire project)

Here is the new code.. you basically need two tests instead of one... so unlike the scene_init.script code above.. here is your new one.

Code: WME Script
  1. global ExitSceneGV;
  2. //Right Stairs
  3. if(Game.PrevScene=="hallway")
  4. {
  5.   if(ExitSceneGV == "hallway_exit01")
  6.   {
  7.     // we went the way we came
  8.         actor.SkipTo(856, 227);
  9.         actor.TurnTo(DI_DOWNLEFT);
  10.   }
  11.   else if(ExitSceneGV == "hallway_exit02")
  12.   {
  13.     // we went around to other side
  14.         actor.SkipTo(147, 231);
  15.         actor.TurnTo(DI_DOWNRIGHT);
  16.   } 
  17. }

There you go that is it.... same as before but this time you are doing more tests on the variable ... you can add as many else (rooms entrances) as you want with this method.



Hope that help!!! Remember i am a beginner as well.. as I learn somthing that confused the hell out of me i will post a tut on how to get past it...

Have fun!!!
« Last Edit: September 24, 2007, 03:06:47 AM by Jyujinkai »
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe
 

Page created in 0.098 seconds with 21 queries.