Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dor Hajaj on Wed 01/08/2018 23:22:50

Title: Click processing when active inventory item is selected
Post by: Dor Hajaj on Wed 01/08/2018 23:22:50
Hi,

I'm trying to achieve the following:
1. Select an item from inventory
2. Left click to use inventory on something
3. Restore normal mouse mode

So, when the player clicks on an inventory item, I use a label attached to the mouse that shows the item name.
After the left click I would like to clear the label and restore the mouse back to the previous mode(interact).

I've tried this in GlobalScript:
Code (ags) Select

else if (button == eMouseLeft) {
      ProcessClick(mouse.x, mouse.y, mouse.Mode);
      if(mouse.Mode == eModeUseinv)
      {
        player.ActiveInventory = null;
        gActiveItemText.Visible = false;
        activeItemText.Text = " ";
      }

But the active inventory item is null when the Use_Inv function is called.

Thanks!
Title: Re: Click processing when active inventory item is selected
Post by: imsomnia212 on Thu 02/08/2018 03:30:12
I don't get what you want. You have a label that's show the ítem name but when you click on the item you want to stop showing the label?
Title: Re: Click processing when active inventory item is selected
Post by: Dor Hajaj on Thu 02/08/2018 06:19:34
Basically yes.
This is how it looks at the moment:
(https://i.imgur.com/25JsUxt.png)
The mouse does not change its icon according to the inventory item selected. Instead, I use the label to indicate the item name.
When the player makes the interaction I would like to clear the field and set the active inventory item to null.
What I have at the moment is the option to do so by clicking the right mouse button, so it happens AFTER the actual Use_Inv event and there is no problem.
When I try to do this as part of the left click event, by the time the Use_Inv function is called the active item is null, and nothing happens.
Title: Re: Click processing when active inventory item is selected
Post by: dayowlron on Thu 02/08/2018 13:52:48
I would place a breakpoint on line 5 in your listing "player.ActiveInventory = null;". Then see if it is being fired when you select your inventory item.
If it is, then the ProcessClick is probably selecting an inventory item and then mouse.mode is eModeUseinv so the if statement is executing.
If not (which I am thinking it wont be because the label still has something in it) then there must be another place where "player.ActiveInventory = null;" is happening.
Title: Re: Click processing when active inventory item is selected
Post by: Dor Hajaj on Fri 03/08/2018 22:48:24
The break point fires.
Looks like the PrcoessClick() runs(and does whatever it does), and then the if statement goes into play and causes the inventory item to be null, which in turn makes the use inventory on something function useless.
What I was trying to ask, let's ignore the code I wrote which does not work, what is the best way the perform an inventory item action on something and clear the mouse, so the inventory item does not remain active after the player used it?
Title: Re: Click processing when active inventory item is selected
Post by: tzachs on Sat 04/08/2018 04:47:24
I believe what's happening here is that when you call ProcessClick, it doesn't process the click immediately, but it enters it into a queue for later processing. You can read this (https://adventuregamestudio.github.io/ags-manual/BlockingScripts.html?highlight=processclick) to get more information on why it's doing this.

You can also verify that by adding the same breakpoint you had before, and also adding a breakpoint in your use inv function and see what happens first.

In terms of best way to clear the inventory, the first question to ask is: are you sure you want to clear the inventory on EVERY inventory interaction? What most games do is clear the inventory after a meaningful interaction with this item when you no longer need it (because if a player wants to try an inventory item on a bunch of places in the room, it's annoying to reselect it every time).
If you don't need it on every interaction you can create a function with the 3 lines (clearing the inventory item and label) and call it from the use inv function (and every meaningful interaction).
If you do want to clear it every time, then one way of doing this would be to wait a frame before clearing the inventory item.
Try adding "Wait(1)" inside the if before clearing the inventory item.
Title: Re: Click processing when active inventory item is selected
Post by: Dor Hajaj on Sat 04/08/2018 09:45:52
Quote from: tzachs on Sat 04/08/2018 04:47:24
In terms of best way to clear the inventory, the first question to ask is: are you sure you want to clear the inventory on EVERY inventory interaction? What most games do is clear the inventory after a meaningful interaction with this item when you no longer need it (because if a player wants to try an inventory item on a bunch of places in the room, it's annoying to reselect it every time).
If you don't need it on every interaction you can create a function with the 3 lines (clearing the inventory item and label) and call it from the use inv function (and every meaningful interaction).
If you do want to clear it every time, then one way of doing this would be to wait a frame before clearing the inventory item.
Try adding "Wait(1)" inside the if before clearing the inventory item.

Well explained!
I think you are correct and clearly I did not give this enough thought. I'll go with the meaningful interaction way.
Can you explain a bit more, what will the Wait(1) achieve? It blocks the game for 1 cycle right?
Title: Re: Click processing when active inventory item is selected
Post by: tzachs on Sat 04/08/2018 18:02:05
Yes, it blocks the current script for one frame, but I think it should free the engine to process the commands in the queue, so it should fire the ProcessClick event.