Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Darryl on June 24, 2015, 10:28:06 PM

Title: Interactive Code Problem
Post by: Darryl on June 24, 2015, 10:28:06 PM
Hi Dear Friends,
I Have amazing problem with "Interactive" code,
Please help me.
But problem:
In scene after left click on Region , I write : this.Interactive=false;
And interactive be false,
But when I go to another scene and come back to scene , interactive don't work and its be true;
In other word this.interactive=false; only work until we are in scene and if we go to another scene and come back , its don't work.!!
I look forward to hear from you.
Best Regards.
Title: Re: Interactive Code Problem
Post by: binary1 on June 24, 2015, 11:13:38 PM
I'm not sure exactly what you mean.  When you click on the region, are you making the region non-interactive?  You could try using the name of the structures as in myRegion.interactive = false; 

If everything resets when you come back in, you could set a global flag something like global canInteract = true; in the game.script.  Then, when you click on the region:

on "LeftClick"
{
  canInteract = false;
  this.Interactive = false;
}

In the init method for the scene, check the flag
if (canInteract == false)
{
   myRegion.Interactive = false;
}

else
{
  myRegion.Interactive = true;
}

I'm not sure if that's what you are looking for.
Title: Re: Interactive Code Problem
Post by: Dan Peach on June 26, 2015, 01:26:18 AM
I think in scene properties, you need to make sure "remember node states" is checked.  If it isn't, the scene will load the initial states each time the scene is loaded.
Title: Re: Interactive Code Problem
Post by: anarchist on June 28, 2015, 12:10:03 PM
Hi Darryl, welcome to the forum.

Dan Peach has provided one solution below. Indeed, "Remember node states" will make sure that the engine remembers changes you made to nodes in scenes.

Alternatively you can use the scene_init.script to achieve this.

Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // scene state
  3. global StateScene;
  4.  
  5.  
  6. // default values
  7. if(StateScene == null)
  8. {
  9.         StateScene.RegionInteractive = true;
  10. }
  11.  
  12. if(StateScene.LetterHotspotVisible){
  13.         var node = Scene.GetNode("region_name");
  14.         node.Interactive = StateScene.RegionInteractive;
  15. }
  16.  

Then, inside the script of the region:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.         var node = Scene.GetNode("region_name");
  4.         node.Interactive = false;
  5.         StateScene.RegionInteractive = false;
  6. }
  7.  

This way, you have the node state inside a global variable. Every time you re-enter the scene, the code in scene_init will run and set Interactive to false. Hope this helps.