Forum rules - please read before posting.

Setting and Getting Inventory Property

edited January 2018 in Technical Q&A
I'm quite happy how far I've already got with this however I've hit a roadblock that I really need some help with from someone who knows what they're doing!

Quick summary of my situation - I have some Inventory items that change depending on how and when the player picks them up, I initially made different copies of each Inventory item to then add the relevant version of the Inventory item (I know I know, I realise this is a poor way to do things especially since there are 4 iterations of each item and so my 7 Inventory items are taking up 28 Inventory slots in the manager and new scenes that I've yet to start will add more unique items once I get onto them). So I finally noticed the Property field in the Inventory Manager and realised that I could be doing this whole thing a lot better so instead of 4 different Inventory items of the same item I thought I could simply adjust a Property value of each item instead.

So I have made a custom action that surprisingly works, I'm not sure where I stand posting the code of a custom action on PasteAll as I had to copy certain code from AC actions to get it properly working. If allowed though then I will post for clarity. The action itself is very simple, it has a drop down box where I select the Inventory item to affect as well as an integer box to enter the value of the new property.

So that action is great for setting the property however I need help with getting the property. Well, I know how to do it in a script however I'm struggling to do this in a user friendly way within an action list via an action. The way I want to do it is similar to the Variable: PopUp Switch action, so I'd like to have an action that has the Inventory item drop down box where you select the Inventory Item you want to check however it should then have 4 different nodes tied to the result of what the specific Inventory items property value is and then based on which is true determines what the next action is run (as mentioned similar to how the Variable: PopUp Switch is used).

Hopefully I've explained myself well enough, I've tried to understand how the Variable: PopUp Switch action is done inside the script however I still only understand the very basics when it comes to coding and I'm struggling to fully understand it all (there are even parts of the custom action I did that I don't fully understand)!

As ever thanks again in advance for any help given.

Comments

  • The Variable: PopUp Switch Action is different from most other Actions in that it the number of output sockets it has can be changed.  This is allowed because it derives from the ActionCheckMultiple class.

    Have your custom "get" Action derive from ActionCheckMultiple instead of Action, and you'll then be able to alter the number of sockets in your ShowGUI function, e.g.:

    numSockets = 4;

    "Checking" Actions generally don't need a Run() function, as they only read data without manipulating them.  What you do need, however, is an override of the End() function, which is used to determine which output socket to follow when the Action is invoked.  Without null error checks in place, all it really needs to do is return a call to ProcessResult() , which generates an appropriate ActionEnd instance based on the correct socket index.  For example:

    override public ActionEnd End (List<Action> actions)
    {
        return ProcessResult (2, actions);
    }


    Will cause the 3rd (counting starts from 0) output socket to be followed.  To make it dynamic, replace the "2" with your own integer variable, and set that integer's value to the value of your popup property.
  • edited January 2018
    Regarding the posting of custom Actions - shared code from AC Actions is generally OK, since they don't work without AC's core scripts.  I'm happy to review anything beforehand through PM if you'd like to be safe, however.  Community contributions are always welcome on the AC wiki.
  • edited January 2018
    @ChrisIceBox

    As with every question I post on here I always try to get as far as I can on my own (as in checking all available help online within this forum, the tutorials, manuals and Unity forums) and I was slightly doubting myself yesterday after posting the above question as I wondered whether I 'gave up' too early when directly asking for help however I am confident in saying that I would have never solved this without your response. At least definitely not in such a simple and effective way, I can't believe all it took was literally a few simple lines of code!

    Anyway it is all working perfectly and more importantly not only working but working in the exact way that I wanted it to which is never always case for me haha! Anyway I'm not sure if anyone else needs something similar however even if just 1 person does then it will be worth me uploading onto the Wiki. Obviously a quick review of the entirety of the code would be appreciated before I upload in case I'm still doing something inefficient or if there are any lines that aren't even needed. So if you don't mind I'll PM you the code and then if ok I'll submit to the wiki.
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.