Hi Guys,
I don't know if you remember but my game uses a lot of unhandled inventory item interactions for my inventory puzzles. As with most games involving Inventory puzzles one needs to be able to remove inventory items at certain points and so I wrote a custom action script to remove the current inventory item as the standard inventory removal method asks for you to tell it which item needs to be removed.
The script... doesn't quite work as planned - Here's a video that show's what it issue is:
Now the script is VEEERY simple. It is literally....
AC.InvItem myItem = AC.KickStarter.runtimeInventory.SelectedItem;
if (myItem == null) return 0f;
KickStarter.runtimeInventory.Remove(myItem);
return 0f;
And as you saw in the video it does do this - But the first time round it, removes the item from the cursor, not the inventory, and every time after that it removes the item from the inventory but not the cursor.
I honestly don't know... how it's doing that. the script reports no errors, nor is there anything seemingly wrong in the game's Console while the game's running.
Thanks.
Comments
The item still being the cursor is due to there not being a restriction in an item needing to actually be in the inventory for it to be selectable - so that others can make use of this in other custom code. To unset the cursor after removing it from the inventory, call:
KickStarter.runtimeInventory.SetNull ();
As for it still being in the Menu, this is because you must also reset Menu display afterwards. Menus are not updated every frame to preserve performance, so you need to tell it to do so manually:
PlayerMenus.ResetInventoryBoxes ();
Arguably, this should be called by the Remove function automatically - I'll consider making that change officially, but the above code should solve the problem.
Also, it might make it easier for you to make your first custom Action derive from ActionCheck, not Action - so that you can do without the need for a Variable: Check Action afterwards, and just use the two output sockets from the custom Action directly.
To make an ActionCheck use the correct output socket when running, you need to add an override CheckCondition function, which returns the output as a bool. This is used instead of the Run() function, assuming the check occurs instantaneously and has no need to run multiple frames:
public override bool CheckCondtion ()
{
InvItem myItem = KickStarter.runtimeInventory.SelectedItem;
The ActionCheckTemplate script shows how the structure of such an Action should be laid out.