Forum rules - please read before posting.

How can I get item data in each container of each scene and modify their rot properties?

I did the time lapse system and the food system. As soon as the global time variable changed (which I monitored with OnVariableChange), the rot value of all the food in the game increased. To do this, I had to get every food data in each container of each scene and modify their rot properties. How do I code to do that?


  • Chris should be able to give you more details, but I've recently dealt with a similar issue - I needed to manipulate container contents so that NPCs would place items in them and sort them, even if the player was not currently in the scene where the containers were.

    The first thing you should probably do is have the containers on DontDestroyOnLoad. Since I don't really do character switching in my game, the easiest way for me to do that was to add the containers as children of the player character, but obviously you don't necessarily need to do it that way, as long as you keep the containers loaded through other means.

    Then I assume you'd have to go through each item in the container's InvInstance array and change the property. I'd need to refer to the scripting guide to know how/if this is possible though.

  • See the Manual's "Inventory scripting" chapter for an overview of how AC's Inventory system works. At runtime, inventory item references are made with the InvInstance class, which both records the original item as well as local data associated with it.

    You can iterate through each Container's InvCollection for valid InvInstances, and then use GetProperty to get that instance's property value - which can then be modified:

    Container[] containers = FindObjectsOfType<Container> ();
    foreach (Container container in containers)
        foreach (InvInstance invInstance in container.InvCollection.InvInstances)
            if (!InvInstance.IsValid (invInstance)) continue;
            invInstance.GetProperty ("Rot").IntegerValue ++;
  • You're both great, and you give me ideas, and I know what to do, okay!

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.