Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Script Cross Scene communication - absolute paths?  (Read 4515 times)

0 Members and 1 Guest are viewing this topic.

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Script Cross Scene communication - absolute paths?
« 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! :-)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
Re: Script Cross Scene communication - absolute paths?
« Reply #1 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
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Script Cross Scene communication - absolute paths?
« Reply #2 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

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.  
Logged

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: Script Cross Scene communication - absolute paths?
« Reply #3 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.
« Last Edit: May 03, 2013, 07:02:21 PM by Jose »
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: Script Cross Scene communication - absolute paths?
« Reply #4 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! :-) 
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/
 

Page created in 0.048 seconds with 21 queries.