Differences

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


kbase:meaecode 2008/02/26 12:47 kbase:meaecode 2010/08/06 21:11 current
Line 58: Line 58:
{{http://img262.imageshack.us/img262/7561/wmetut01ow8.png}} {{http://img262.imageshack.us/img262/7561/wmetut01ow8.png}}
 +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.
-------------UNDER CONSTRUCTION----------------- +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. 
--------------------NEED TO STEP OUT FOR A FEW MINS.. BRB TO FINISH THIS---------------------------------- + 
-------------UNDER CONSTRUCTION-----------------+So.... the Kitchen and the ballroom both have this code on an entity witch you left click to enter the ballroom. 
 + 
 +<code script>on "LeftClick" 
 +
 +  actor.GoToObject(this); 
 +  Game.ChangeScene("scenes\ballroom\ballroom.scene"); 
 +}</code> 
 + 
 +Ok... enough background.... 
 + 
 + 
 +====Passing a global variable between scenes==== 
 + 
 +So let's do this.... The way it will work is that we will define a variable, which is passed from one scene to the other. Which can then be tested in the hallway scene, thus enabling the hallway to identify which 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 script>on "LeftClick" 
 +
 +  global ExitSceneGV = "kitchen2hallway"; 
 +  actor.GoToObject(this); 
 +  Game.ChangeScene("scenes\ballroom\ballroom.scene"); 
 +}</code> 
 + 
 +==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 script>actor.SkipTo(400, 400); 
 +actor.Direction = DI_DOWN;</code> 
 +3) Replace them with these lines. 
 +<code script>global ExitSceneGV ; 
 +//Enter from Kitchen 
 +if(Game.PrevScene=="kitchen") 
 +
 +  if(ExitSceneGV == "kitchen2hallway") 
 +  { 
 +        actor.SkipTo(400, 400); 
 +        actor.Direction = DI_DOWN; 
 +  } 
 +}</code> 
 + 
 +==Pause and understand what has happened== 
 + 
 +The scene initialization 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. Which is 
 +<code script>actor.SkipTo(400, 400); 
 +        actor.Direction = DI_DOWN;</code>  
 +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 script>on "LeftClick" 
 +
 +  global ExitSceneGV = "ballroom2hallway"; 
 +  actor.GoToObject(this); 
 +  Game.ChangeScene("scenes\ballroom\ballroom.scene"); 
 +}</code> 
 +And the scene_init.script for the hallway is now 
 +<code script>global ExitSceneGV ; 
 +//Enter from Kitchen 
 +if(Game.PrevScene=="kitchen") 
 +
 +  if(ExitSceneGV == "kitchen2hallway") 
 +  { 
 +        actor.SkipTo(400, 400); 
 +        actor.Direction = DI_DOWN; 
 +  } 
 +
 +//Enter from Hallway 
 +if(Game.PrevScene=="ballroom") 
 +
 +  if(ExitSceneGV == "ballroom2hallway") 
 +  { 
 +        actor.SkipTo(400, 400); 
 +        actor.Direction = DI_DOWN; 
 +  } 
 +}</code> 
 + 
 +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!!!!!! 
 + 
 +===== More than one entrance point to a single room ===== 
 + 
 +If you have a U shaped hall witch exits into a single room but on different sides you need to slightly modify this code. 
 +{{http://img444.imageshack.us/img444/9076/wmetut02ts3.png}} 
 +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 script>global ExitSceneGV; 
 +//Right Stairs 
 +if(Game.PrevScene=="hallway") 
 +
 +  if(ExitSceneGV == "hallway_exit01") 
 +  { 
 +    // we went the way we came 
 + actor.SkipTo(856, 227); 
 + actor.TurnTo(DI_DOWNLEFT); 
 +  } 
 +  else if(ExitSceneGV == "hallway_exit02") 
 +  { 
 +    // we went around to other side 
 + actor.SkipTo(147, 231); 
 + actor.TurnTo(DI_DOWNRIGHT); 
 +  }   
 +}</code> 
 +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. 
 + 
 + 
 +====Goodbye==== 
 +Hope that help!!! Remember i am a beginner as well.. as I learn something that confused the hell out of me i will post a tut on how to get past it... 
 + 
 +Be excellent to each other and Party on Dudes 
 +–Jyujinkai
 
kbase/meaecode.1204026457.txt.gz · Last modified: 2008/02/26 12:47 by Jyujinkai
Recent changes RSS feed Creative Commons License Driven by DokuWiki