Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: TheMagician on Sat 05/03/2005 10:38:32

Title: right click in custom inventory GUI (SOLVED)
Post by: TheMagician on Sat 05/03/2005 10:38:32
Hi everybody!

I want to script a right click while the (custom) inventory GUI is on which deselects the current item.
But I do NOT want to enable "handle inventory clicks in script".

Is this possible?


Title: Re: right click in custom inventory GUI
Post by: Pumaman on Sat 05/03/2005 12:25:27
No, if you want to manually handle clicks on the inventroy then you will need to enable the Handle Inventory Clicks in Script option -- that's what it's for, after all.
Title: Re: right click in custom inventory GUI
Post by: TheMagician on Sat 05/03/2005 12:39:51
Ok.
Now, I experimented with custom scripting of inventory clicks.

on_mouse_click:

if (button == LEFTINV) {
SetActiveInventory(game.inv_activated);
}
if (button == RIGHTINV) {
//script that does what I want :-)
}

but how do I script the following:
click with an inventory item selected on another item ... the interaction between the items gets run and then the cursor goes back to the default "pick an inventory item" pointer.

I tried

if (character [EGO].activeinv == -1) {
Ã,  RunInventoryInteraction (game.activeinventory(or what it is called), GetCurserMode() );
}
else if (character[EGO].activeinv > -1) {
Ã,  RunInventoryInteraction (game.activeinventory(or what it is called), MODE_USEINV);
Ã,  SetActiveInv(-1);
}

that doesn't work.

Any ideas?
Title: Re: right click in custom inventory GUI
Post by: Ashen on Sat 05/03/2005 12:57:45
Where have you put the second bit of code?
What is/isn't it doing?(i.e. is it running the interaction but not changing the cursor, is it doing nothing, etc.)
Title: Re: right click in custom inventory GUI
Post by: TheMagician on Sat 05/03/2005 13:10:35
Hi Ashen,

well, I put the code in the "on mouse click" function in the global script.

If I do

}
else if (character[EGO].activeinv > -1) {
  RunInventoryInteraction (game.activeinventory(or what it is called), MODE_USEINV);
   SetActiveInv(-1);
}

it does nothing at all

if I remove the line SetActiveInv(-1); then the Interaction gets run but the cursor does of course not reset ...
Title: Re: right click in custom inventory GUI
Post by: Ashen on Sat 05/03/2005 13:19:51
It might be that the SetActiveInv (-1); is being called before the interaction has processed. Try adding a Wait(1);, e.g.

else if (character[EGO].activeinv > -1) {
  RunInventoryInteraction (game.activeinventory(or what it is called), MODE_USEINV);
  Wait (1);
  SetActiveInv(-1);
}

Alternatively, try adding the SetActiveInv (-1); to the end of the 'use inventory on this item' interactions, e.g.

  // script for inventory1: Use inventory on this item
  if (character[EGO].active inv == 2) {
    Display ("You used item 2!");
  }
  else if (character[EGO].active inv == 3) {
    Display ("Why would I want to use item 3?");
  }
  SetActiveInv (-1);


You'd have to do this for every item though, so it's probably a last resort.
Title: Re: right click in custom inventory GUI
Post by: TheMagician on Sat 05/03/2005 13:26:30
QuoteIt might be that the SetActiveInv (-1); is being called before the interaction has processed. Try adding a Wait(1);, e.g.

I thought about that, too and added a Wait ... the result is pretty strange (the whole GUI gets blacked out for a split second)  ... and nothing happens (no interaction).

QuoteAlternatively, try adding the SetActiveInv (-1); to the end of the 'use inventory on this item' interactions, e.g.

You'd have to do this for every item though, so it's probably a last resort.

I have not tryed that yet as I am at university right now and don't have my game with me :-(
Title: Re: right click in custom inventory GUI
Post by: Pumaman on Sat 05/03/2005 18:51:55
As it happens, I think your problem here is something I just wrote a page about:

http://www.adventuregamestudio.co.uk/manual/BlockingScripts.htm

ie. RunInventoryInteraction is queuing the inventory interaction script, but because you're SetActiveInventory(-1) is happening first it isn't actually running the interaction, if you see what I mean.
Title: Re: right click in custom inventory GUI
Post by: Scorpiorus on Sat 05/03/2005 20:13:24
Quote from: TheMagician on Sat 05/03/2005 13:26:30
QuoteAlternatively, try adding the SetActiveInv (-1); to the end of the 'use inventory on this item' interactions, e.g.

You'd have to do this for every item though, so it's probably a last resort.

I have not tryed that yet as I am at university right now and don't have my game with me :-(
Yeah, having SetActiveInv(-1) running just after the inventory item interaction should solve the issue.
Considering the fact the scripts are queued up (see Chris' page about blocking), you can probably do a little trick to avoid adding SetActiveInv(-1) for each interaction. Try adding a dummy inventory item and have its LookAt script: SetActiveInventory(-1);
Next make AGS queue it up, like this:

else if (character[EGO].activeinv > -1) {
  RunInventoryInteraction (game.activeinventory(or what it is called), MODE_USEINV);

  // will do SetActiveInventory(-1) after the interaction script:
  RunInventoryInteraction (DUMMY_ITEM, MODE_LOOK);
}
Title: Re: right click in custom inventory GUI
Post by: TheMagician on Sun 06/03/2005 16:44:03
Thanks for your help!

I was able to solve the problem with Ashens suggestion:

QuoteAlternatively, try adding the SetActiveInv (-1); to the end of the 'use inventory on this item' interactions

I also tried your clever workaround, Scorpiorus. It works as well!

Thanks again.
Stefan