Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: jimm84 on May 01, 2013, 11:07:49 PM

Title: Script Cross Scene communication - absolute paths?
Post by: jimm84 on May 01, 2013, 11:07:49 PM
Hello again! I was wandering if someone could help with this. I'm trying to get a script to communicate with a previous scene (we'll call it scene1) when the sprite object is interacted with and an animation is triggered I want an object/item to vanish from scene one. Now... can I in the script place an absolute path (scene1/item1.stone.Visible = false;) or would I need to do this by a different means?

////////////////////////////////

on "Stone"
{
  actor.Talk("That should do it!");
  boulder.Play();
  Game.Interactive = true;
  Game.DropItem("stone");
  Game.DeleteEntity("stone");
  var stoneonfloor = Scene.GetNode("stone");
  stoneonfloor.Active = false; (the bit that should communicate?)
  }

Thanks for you help all! :-)
Title: Re: Script Cross Scene communication - absolute paths?
Post by: hubertMichael on May 01, 2013, 11:34:54 PM
just make some global variable in base.inc

global obj_vanish; //object to vanish in scene1


when you trigger your animation change your variable

obj_vanish = true;

at scene1 scene_init.script

var yourobj = Scene.GetNode("your_object");
if(obj_vanish) yourobj.Active = false;

if I understand you correctly
Title: Re: Script Cross Scene communication - absolute paths?
Post by: anarchist on May 02, 2013, 05:45:04 PM
Hello again jimm84.

This is a very common functionality in adventure games and this is one use for global variables. First, please refer to our previous discussion http://forum.dead-code.org/index.php?topic=5382.msg30555#msg30555 (http://forum.dead-code.org/index.php?topic=5382.msg30555#msg30555)

So, you have two scenes, the one is the current (StateCurrent) and the one you need to change (StateOther). In each scene_init.script you will have the following:

in current scene's scene_init.script
Code: WME Script
  1. global StateCurrent;
  2.  

in other scene's scene_init.script
Code: WME Script
  1. global StateOther;
  2.  

in the script of the other.

This still doesn't help you though, because the current scene script cannot "see" StateOther. This can easily be fixed in two ways. Either you declare the "other" scene variable in your current scene's scene_init.script or you declare both once in your base.inc and this way all the scripts of the game will be able to access it. Below is a solution for the first way, using the script you provided:

Code: WME Script
  1. on "Stone"
  2. {
  3.   global StateOther;
  4.   actor.Talk("That should do it!");
  5.   boulder.Play();
  6.   Game.Interactive = true;
  7.   Game.DropItem("stone");
  8.   Game.DeleteEntity("stone");
  9.   StateOther.StoneFloor = false;
  10. }
  11.  

an in the other scene's scene_init.script
Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // scene state
  3. global StateOther;
  4.  
  5. // default values
  6. if(StateOther==null)
  7. {
  8.         StateOther.Visited = false;
  9.         StateOther.StoneFloor = true;
  10. }
  11.  
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // setup scene according to state variables
  14. if(StateOther.StoneFloor)
  15. {
  16.         var stoneonfloor = Scene.GetNode("stone");
  17.         stoneonfloor.Active = false;
  18. }
  19.  
  20. ////////////////////////////////////////////////////////////////////////////////
  21. if(!StateOther.Visited)
  22. {
  23.   StateOther.Visited = true;
  24.  
  25.   // this is our first visit in this scene...
  26. }
  27.  
Title: Re: Script Cross Scene communication - absolute paths?
Post by: Jose on May 03, 2013, 03:51:24 PM
As a slightly variant of using global variables, you can also define the flag stoneonfloor as an attribute of the Game object.
Title: Re: Script Cross Scene communication - absolute paths?
Post by: jimm84 on May 12, 2013, 08:36:53 AM
Excellent! thank you all! I have now managed to to get the object to remove itself from the scene... all part of the learning I suppose.

Big thanks! :-)