Forum rules - please read before posting.

Remove current Inventory Item

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

  • edited November 2017
    Thank you for the clear explanation!

    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.
  • Thanks, That fixed the issue correctly. 

    As for upgrading my action - I'm not that advanced as coding (obviously) as while I get the concept of what you're saying, I'm not sure where I'd put it. 

    My InvVar script looks as follows:
        
    AC.InvItem myItem = AC.KickStarter.runtimeInventory.SelectedItem;
                    if (myItem == null) return 0f;
                    CurrentInvPropVal = (myItem.GetProperty(5).val == 1);
                    AC.GlobalVariables.SetBooleanValue (9, CurrentInvPropVal);
    return 0f;

    My guess is that I'd add it before Return 0f; But I'm not very confident on the loop around from the active action to the GUI interface in the Action list view
  • The GUI for "checking" Actions is automatic, in that the "condition is met / not met" sockets and labels are added for you.

    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;
      if (myItem == null) return false;
      return (myItem.GetProperty(5).val == 1);
    }

    The ActionCheckTemplate script shows how the structure of such an Action should be laid out.
  • Oh I didn't even notice there was an ActionCheckTemplate! I'll check it out tomorrow and hopefully I can work it out. Thanks so much! That'll be a great help!
  • Actually, curiosity won out. So I gave it a go and it works wonderfully. I'm not loading it into a variable anymore am I, So I can essentially wipe that global var out - Once I've recoded my scripts obviously..

    It does give me a warning though - Unreachable code detected. 

    Could this be to do with the formatting of the scripts? Often when I load it in MS Visual Studio it tells me my endings are inconsistent, But If I pick Windows, which is my system, I get a error after from AC that the script no longer is derived from any AC classes. So I'm should I be choosing mac when it wants me to consolidate a script format?
  • It'll probably be down to some code return beneath a "return" statement, which means it can't be reached by the compiler.  Without seeing the code I can't comment where it would be, but the error should come with line endings that you can use to trace the problem.
  • I worked it out - I had an extra return false; Warning is all gone now. Thanks for your help!
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.