Forum rules - please read before posting.

Getting Properties of items inside containers?. And getting popup totals.

Hello there!

1.
I was trying to build a little system, and while making the custom scripts, I hit the wall.

As my coding was failing, Inspecting the Scripting guide, looks to me like the only checks I can make to containers in terms of "numbers" are Total number of items inside, and total copies of the same item (Quite useful both, but not this time).

Looks like things like "GetTotalIntProperty(property ID)" and such kind of functions, are only available to check on player inventory, and not containers. (I had the previous sense that they were alike, capable of taking the same queries but looks like I was mistaken once I tried).

Am I right, I can't?. If so, it is possible that containers scripting could be expanded in the future as to get all the kind of queries that are available to player inventory?

(The general objective of it is to be able to use Containers as complex systems where, as a random example, if a container is an Alchemy cauldron, and the player introduces 1 to 4 individual and different ingredients (inventory items) with properties like "Blue: int X", "Red: int X," Yellow: int X", etc, results in a Alchemy Cauldron that can show values of the total color combined of each property (so for example, it can create a resulting a potion with the same propierties but with a simple sum of all previous properties.

I understand I could do this (even with an action list), if I do individual check of every possible item that can be inside or not the container to check every property separately and combine them later, but this workaround is an infinite work as my intention is using a pool of hundreds of possible inventory objects. (Thing that is no effort at all if I can just update the container linked varaibles with the sum of individual properties via script).

2
I was also trying to do this for the container, but as I do not even know how (or if it can be) calculated even for items on the player inventory, I'll ask.

How can I get the total number of instances of particular results of particular popup variables?

I think I can get the popup result of One item asking "GetPopupProperty(int)", but can I get the totals?
For example, if I have 10 different inventory items with a popup property (whose values are for example Summer, Winter, Autumm....

Can I do a check where I'll know how many total items have Summer, Winter, Autumm?

(I can just use another logic to do this, but as I was asking question number 1 I thought to ask it too).

Lots of thanks, and congratulations for the continuous updates of Adventure Creator, is an awesome engine and is always improving!

Comments

  • GetTotalIntProperty etc are a part of the InvCollection class - which holds the raw inventory item data for both Containers and the Player.

    The functions within the Container class itself are just helpers - if you read its InvCollection property, you can get the raw data and access to those property functions, i.e.:

    Container myContainer = ...
    int total = myContainer.InvCollection.GetTotalIntProperty (myPropertyID);
    

    How can I get the total number of instances of particular results of particular popup variables?

    A PopUp variable/properties raw value is just an integer that represents its index in the array. You can iterate through an InvCollection's InvInstances list, and compare both their property ID and value:

    int GetTotalPopUpPropertyValue (InvCollection invCollection, int propertyID, int value)
    {
        int result = 0;
        foreach (InvInstance invInstance in invCollection.InvInstances)
        {
            if (!InvInstance.IsValid (invInstance)) continue;
            InvVar invVar = invInstance.GetProperty (propertyID);
            if (invVar != null && invVar.type == VariableType.PopUp && invVar.IntegerValue == value)
            {
                result ++;
            }
        }
        return result;
    }
    

    Usage would then be something along the lines of:

    int seasonPropertyID = ...
    int numWinter = GetTotalPopUpPropertyValue (myContainer.InvCollection, seasonPropertyID, 0);
    int numSpring = GetTotalPopUpPropertyValue (myContainer.InvCollection, seasonPropertyID, 1);
    
  • Wow! Lots of thanks. Works like a charm both of it!

    This engine is always improving... and making questions here has been my best way to keep improving coding along these years ;)

  • Ups! Just a little problem.
    After achiving being able to modify propierties from script (as I did not see anything in the scripting guide to "Set Property" but there was an actionlist to change propierties values so... It must be possible! So I achived it with this script

     inventoryContainer = thiscontainer.InvCollection;
                int propertyIDToDeduct = 0; // Current Health Propierty
    
                if (inventoryContainer == null)
                {
                    ACDebug.LogError("Inventory container is not assigned!");
                    return 0f;
                }
    
                // Loop through each inventory item in the specified container
               foreach (InvInstance invInstance in inventoryContainer.InvInstances)
    {
        if (invInstance != null)
        {
            // Get the property of the inventory instance by ID
            InvVar property = invInstance.GetProperty(propertyIDToDeduct);
    
            // Check if the property exists and is of type integer
            if (property != null && property.type == VariableType.Integer)
            {
                // Deduct 1 from the property's integer value
                property.IntegerValue -= 1;
    

    This have worked well, Saves and Loads an all. And the instance of the item gets down (It's a sort of health that goes down when the item (a person) is inside the container (a place) for a turn.

    Thing is, I've set that I cannot put people in the container if their current health is 0.

    Problem is, as was quite a simple thing, I was checking with the Action of Property to Variable, Then check the variable against 0, to not allow the item back in the container.

    After some testing, I discovered that the value that item's propierty is checked against the variable, is the original propierty of the item, not the modified property of the instance.

    May that be the problem? Can I fix that modifying the Action script so it not only checks invitems but invinstances maybe?

    Do I have to make my own script better?

    It can be a problem that I have no Player in the project?
    (I just started a project and inventory management worked without a player in scene (thing that I don't remember possible some versions ago).

    I ask because as not having a Player in the project, I don't even know where the Player's inventory is... And I don't know what kind of other ramifications may have not having a player in the project (as in other projects I always used a Player).

    Thanks!!

    PS: Am I right that there is no direct functions to just "SetProperty" or am I wrong again? xD

  • If the Inventory: Property to Variable Action's Method is set to Property To Variable, you can check Get 'live' values? to have AC reference the InvInstance in the Player's inventory at runtime - as opposed to the original in the Inventory Manager.

    AC will look for the first item of the chosen type, however. If you need to access a specific InvInstance, you'll need to access it through scripting.

    I ask because as not having a Player in the project, I don't even know where the Player's inventory is...

    The on-screen Player character and is independent from their inventory - you can still use the Inventory Actions and access playerInvCollection with or without a Player present.

  • edited December 2023

    Using the "Get Live Features" was a thing I tried thinking it could be related.
    Strangely enough, it gave me a "bug" that I didn't reported because I guessed it was a totally unrelated thing and I thought my problem was elsewhere.

    For some reason, when the "live" is ticked I get a ACdebug log saying that can't find the item (Cannot find Inventory item with ID 0 in the Player's inventory) (Whatever item I try, gaves me the correspondent ID as not found) I check on the script and is a log it gives specificially when UseLiveValue is used and the InvInstance is not valid.

    You said not having a player may have nothing to do, and I tried and yes; It is not relevant having or not a player with inventory on the scene for the matter of this "bug".

    The inventory item is supplied via parameter using the "ContainerAdd" Event, the parameter that is automatically handled by the Event.

    In case that was the problem (suppling it via parameter), I tried other options, like always checking an specific inventory item. That didn't reported reported a DebugLog when using other items (by using them I mean putting them on the container), except when using the specific item, making me think,** that the script fails because It can't read the live value inside the container.** ActionInvProperty script is checking runtimeinventory.instance, I don't know if that has access to containers too.

    I don't know but is my guess.

  • Well, personally I resolved this issue just pre-recording the Live value of the item with the OnInventorySelect event, so when the variable is checked on OnContainerAdd event, is not trying to get the data from the item inside container, so at least it works that way.

    I guess I'll keep finding problems now and then trying to make such an intensive use of properties.... So I'll try to code everything that I can think out about properties modification to see if the project is posible.

  • edited December 2023

    For some reason, when the "live" is ticked I get a ACdebug log saying that can't find the item (Cannot find Inventory item with ID 0 in the Player's inventory

    If you're getting this error, and the item with this ID is in the Inventory, share the exact steps to recreate the issue and I can look into it.

  • If you're getting this error, and the item with this ID is in the Inventory, share the exact steps to recreate the issue and I can look into it.

    Well, the case is that when the ActionInvProperty action runs, and the warning is given, the item is not in the inventory, is on a container.

    So I guess the debug log is totally fair and not a bug per se; The Item can't be found in the inventory. I guess the problem (if it is a problem) is just that the user can't use that action if the item is on a container.

    If you need, Long Explanation: (Steps)
    While for my working purposes (in this case) it's fixed, for example now the warning shows when selecting the inventory item from the container to get it back to the player (but is just a harmless info debuglog now for me).

    That's because now the property check occurs in the OnInventorySelect event instead of what I was trying to do before, checking the item OnContainerAdd.

    Well, basically the step is just to click on an inventory item inside a container using for example OnInventorySelect event. (Or as I did before, trying to use the ActionInvProperty on OnContainerAdd);
    the ActionInvProperty is just not able to get the ID from the item from a container.

    The warning only shows when the Get Live Values is checked. When that's unchecked, there is no warning.

    In the other hand, My logic didn't implied not using a live value, I cannot remember well; I only know that if I didn't use live values, my logic will won't work well, but I didn't get a warning.

  • Well, the case is that when the ActionInvProperty action runs, and the warning is given, the item is not in the inventory, is on a container.

    Understood, thanks for clarifying. I'll have a think how this situation might be catered for.

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.