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: Game.Interactive and mouse click  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Game.Interactive and mouse click
« on: January 20, 2016, 12:13:12 PM »

Hello, I'm up against a problem.
I have an inventory that I open by pressing a button and I close by pressing a mouse button away from it.
What I want to achieve is that when the inventory is visible, if the player moves the mouse in the scene, all interactive objects do not respond to the passage of the cursor.
I have tried several ways, either by acting on the scripts of objects, in game.script and in game_loop.script without luck.
Currently I have found that the following lines of code conduct the majority of what I want to do

in game_loop.script

Code: WME Script
  1.  
  2.   var ActObj = Game.ActiveObject;
  3.  
  4.   // if the inventory is visible and the player goes out from it
  5.   if(Game.InventoryVisible == true && ActObj.Type != "window" && ActObj.Type != "item")
  6.   {
  7.         // if an item is selected close inventory
  8.         if(Game.SelectedItem != null)
  9.         {
  10.                 btnInv.Visible = true; // button to open inventory
  11.                 Game.InventoryVisible = false;
  12.         }
  13.         else
  14.         {
  15.          // otherwise if the player comes from the inventory without any selection I apply Game.Interactive = false
  16.          // so objects in the scene are not responding on mouse
  17.          if(Game.Interactive == true)
  18.                 Game.Interactive = false;
  19.         }
  20.   }
  21.   // if the cursor is on the inventory
  22.   else if(Game.InventoryVisible == true && (ActObj.Type == "window" || ActObj.Type == "item"))
  23.   {
  24.            // Game.Interactive = true and I can interact with items
  25.            if(Game.Interactive == false)
  26.                 Game.Interactive = true;       
  27.   }
  28.  
  29.  


but then of course, being the game Game.Interactive = false while the cursor is out of inventory, clicking with the mouse everywhere inventory can not be closed because the event is not read.

Is there a way to ask the engine to check a click of the mouse while it is in Game.Interactive = false?

Have you any other suggestions?

Thanks
Logged

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 192
    • View Profile
Re: Game.Interactive and mouse click
« Reply #1 on: January 20, 2016, 03:31:26 PM »

with most windows you can do this by setting the ingame attribute, I don't know if this functionality extends to the inventory though
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: Game.Interactive and mouse click
« Reply #2 on: January 20, 2016, 05:52:44 PM »

Hello eborr,
I believe you mean Menu or Exclusive because if I understood correctly InGame is used for other purposes ..?
Unfortunately it seems that with these options I will not be able to get what I want.
I have done some testing but in one case I have to close the window by itself and not with a mouse click outside it, in the other case the events mouseentry() and mouseleave() are not hidden.
I'm working on a couple of scripts that would seem to work, if all goes well I'll post my method, it may be useful to someone.
Thank you
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Game.Interactive and mouse click
« Reply #3 on: January 20, 2016, 07:20:15 PM »

Another way could be placing another window or a region entity (for all the scenes) above everything, but under the inventory, so every mouse related event would be intercepted.
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: Game.Interactive and mouse click
« Reply #4 on: January 20, 2016, 08:00:14 PM »

Oh yes, this is a really good idea! Quick and efficient.
I could use an entity region and enable / disable it as needed.
I'll try this solution surely, in any case, I'lll post my solution that is much more complex and it could be adapted to other situations, for example in case you want to inactivate only specific objects.
Thanks  ::thumbup
Logged

valter.home

  • Supporter
  • Occasional poster
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 55
    • View Profile
Re: Game.Interactive and mouse click
« Reply #5 on: January 21, 2016, 10:18:51 AM »

Hello, this was my job:
create a script for every room (with the same name) that includes all the objects you want to disable, and insert it in the folder "scr" of the room, like this:

inter_obj.script
Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. var objArray = new Array();
  4. objArray[0] = "ticket";
  5. objArray[1] = "pc_call";
  6. objArray[2] = "monitor";
  7. objArray[3] = "table";
  8. objArray[4] = "door";
  9. objArray[5] = "key";
  10. objArray[6] = "photo";
  11. objArray[7] = "tv";
  12. objArray[8] = "exit_Init";
  13. objArray[9] = "keyboard";
  14. objArray[10] = "f9";
  15. objArray[11] = "repeat";
  16. objArray[12] = "phone";
  17.  
  18. var change_state;
  19.  
  20.      change_state = true;
  21. else change_state = false;
  22.        
  23. var i = 0;
  24. while(i < objArray.Length)
  25. {
  26.      var inter_obj = Scene.GetNode(objArray[i]);
  27.      inter_obj.Interactive = change_state;
  28.      i = i + 1;
  29. }
  30.  

create a script to be included in the folder "scripts" like this:

base_inter_obj.script
Code: WME Script
  1. function f_base_inter_obj()
  2. {
  3.      var strScene = new String(Scene.Name);
  4.      var separator = new String("\ ");
  5.      separator = separator.Substr(0,1);
  6.      var inter_obj = "scenes" + separator + strScene + "\scr\inter_obj.script";
  7.      Game.AttachScript(inter_obj);
  8.      while (Game.IsScriptRunning(inter_obj))
  9.      {
  10.           Sleep(1);
  11.      }
  12.      Game.DetachScript(inter_obj);
  13. }
  14.  

In the code, after the various calls that open and close the inventory, call the function this way

Code: WME Script
  1. // or Game.InventoryVisible = true;
  2. f_base_inter_obj();
  3.  

Of course where you want to call the function use * #include "scripts\base_inter_obj.script" *.

All works perfectly but if, like me, you must hide all objects at the same time the way suggested by Azrael is much faster.
Simply create an Entity Region for every room (with same name) in the same size of the room and leave it hidden.
So two simple lines of code:

Code: WME Script
  1. var hideshow_obj = Scene.GetNode("hide_obj");
  2. if(hideshow_obj.Active) hideshow_obj.Active = false;
  3.  

or

Code: WME Script
  1. var hideshow_obj = Scene.GetNode("hide_obj");
  2. if(!hideshow_obj.Active) hideshow_obj.Active = true;
  3.  

As you see, I use this way to use the special character * \ * to create the string of path:

Code: WME Script
  1.       var separator = new String ("\ ");
  2.       separator = separator.Substr(0.1);
  3.  

Does anyone know if there is a different way such as the * ~ * before * " * ?
« Last Edit: January 21, 2016, 10:24:09 AM by valter.home »
Logged
 

Page created in 0.318 seconds with 22 queries.