Forum rules - please read before posting.

Add Function when clicking on selected item in inventory

The title may be a bit confusing but here's the scenario, I have a scroll in the inventory which runs a code that when selected, its Y-Position goes up and is visible to the camera. Now when I click on the scroll again, I want it to go down again. I tried the combine event and added a combine event on itself.The scroll goes down when I deselect the scroll using unhandled combine events. I want this to happen when I click on the item itself too. Thanks :)

Comments

  • I'm afraid I find the whole thing a bit confusing - how is the scroll made visible to the camera?  Is it not before?

    It's probably easier to make a separate inventory item for when the scroll is changed, and then use the "Inventory: Replace" Action to swap one for the other.  You can then define a Use interaction for it to run what you need when you click on this changed scroll.
  • Oh, here's the scenario, the scroll is in the inventory box (it's visible there) but in the user's view it's not. To make it simple, the scroll is like a gun that when equipped is held by the player in a fps shooting game. If it's equipped it's held, if not, it goes back down. and is not visible in the camera.

    I have the function for the equip scroll function already, the scroll just goes up and the scroll is then visible. The unequip function works alright too. it just does the same thing in reverse.

    I have the equip function attached to the "on use" event on the scroll item in the inventory. I also have the unequip function attached to the unhandled combine to unequip the scroll whenever the player wants to select another item. But my problem is that whenever I click the scroll item on the inventory box while the scroll itself is equipped. The unequip function doesn't apply.

    All in all what I want to do is to be able to add a function where when the item is active. If you click on the item again, a function or actionlist is ran.

    Please do tell me if it is still confusing. Thanks :)
  • The scroll is made visible to the camera by making its Y Position go up (it is parented to the main camera)
  • That's clearer, thank you - so you want the scroll to become visible in the scene, but also selected as an inventory item (i.e. changing the cursor)?

    Using an item on itself will just de-select it - you can't define an interaction for that, unhandled or otherwise.  However, it will invoke the OnInventoryCombine custom event, which has parameters for both items involved - so you can use this to check if the item was used on itself, and react accordingly.

    See the bottom of the "Inventory scripting" chapter of the Manual, the one on "Custom events", as well as this tutorial.  Shout if you need more specific help after going through those, but that's going to be the avenue to go down - unless you try the replace method I suggested above.
  • Yes, I have tried to combine the scroll on itself but it's not working. I thought it would work but it doesn't which I thought was weird. It just deselects the scroll and doesn't carry out the actionlist attached to it. I will check out the Inventory scripting though thanks :)
  • I found a good solution for my problem, I'm sorry if I didn't get your first suggestion, but it was my bad, thanks a lot for your answer. Here's the link where I got your answer:
  • Like I said: using an item on itself doesn't run an ActionList - only deselects it.  To clarify my first suggestion, I was saying you can replace the item so that you're not using the item on itself, but another item.
  • Thank you, it was my own mistake that I misunderstood what you said. As always, thanks captain! :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.