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: RightClick Inventory  (Read 3090 times)

0 Members and 1 Guest are viewing this topic.

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
RightClick Inventory
« on: March 10, 2012, 02:01:40 PM »

Hello everybody!
I was trying to create an inventory that appears when you rightclick on the screen. I've been able to do that using this simple piece of code on Game.script:

Code: [Select]
on "RightClick"
{
 
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }
 
   Game.InventoryVisible=true;
 }

The inventory is closed when you move the mouse outside of it:

Code: [Select]
if(Game.MouseY > 487 || Game.MouseY <120 || Game.MouseX > 635 || Game.MouseX <160 || Game.ResponsesVisible || !Game.Interactive) Game.InventoryVisible = false;
The problem is this: the code works, but the game won't read the RightClick command anywhere else in the game... for example, if I put a RightClick event on an object's script:

Code: [Select]
on "RightClick"
{
  Game.Interactive=false;
  actor.Talk("A voler essere onesti ho un paio di monete di ottone e basta.");
  Game.Interactive=true;
}

The program doesn't do a thing. What I want to achieve is to have the Righclick as default command to examine, but when I rightclick on a point in the screen where there's nothing active, as objects or entities, the inventory is automatically loaded.
How the code should look like?
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: RightClick Inventory
« Reply #1 on: March 11, 2012, 12:03:21 AM »

Try to make it GoExclusive
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: RightClick Inventory
« Reply #2 on: March 11, 2012, 10:09:39 AM »

You will need to make the RightClick handler in game.script a bit more complicated:

Code: WME Script
  1. on "RightClick"
  2. {
  3.   // there's an inventory item selected
  4.   if (Game.SelectedItem != null)
  5.   {
  6.     Game.SelectedItem = null;
  7.     return;
  8.   }
  9.  
  10.   // we right-clicked some object
  11.   if (Game.ActiveObject != null)
  12.   {
  13.     // can the object handle right-click?
  14.     var actObj = Game.ActiveObject;
  15.     if (actObj.CanHandleEvent("RightClick")
  16.     {
  17.       // yes -> reroute the event to the object
  18.       actObj.ApplyEvent("RightClick");
  19.       return;
  20.     }
  21.   }
  22.  
  23.   // otherwise just open the inventory
  24. }
  25.  

You will probably find your proposed behaviour is not very user friendly, because the player will have to look for "empty" spots on the screen to open the inventory, but it's a matter of design decisions.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

The Man

  • Occasional poster
  • **
  • Karma: 1
  • Offline Offline
  • Posts: 67
    • View Profile
Re: RightClick Inventory
« Reply #3 on: March 18, 2012, 07:35:12 PM »

Thanks for the answer AND the advise... in the end I managed to insert The Luggage that follows Rincewind during the game. When You leftclick it, the inventory is shown!
I don't have the ability to allow user to modify the dimension of the inventory box during the game(As   in Discworld 2), but that should do that in any case!

Thank you again!
Logged
 

Page created in 0.05 seconds with 20 queries.