Click processing when active inventory item is selected

Started by Dor Hajaj, Wed 01/08/2018 23:22:50

Previous topic - Next topic

Dor Hajaj

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

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!

imsomnia212

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?
Are u a tuna?

Dor Hajaj

Basically yes.
This is how it looks at the moment:

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.

dayowlron

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.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Dor Hajaj

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?

tzachs

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 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.

Dor Hajaj

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?

tzachs

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.

SMF spam blocked by CleanTalk