[Solved] Some trouble with my homebrew Inventory setup.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

[Solved] Some trouble with my homebrew Inventory setup.

Post by Nash »

My problem basically is, when I type "give TestItem 10" (or any amount > 1), it seems that AttachToOwner is only execute once. I've looked hard at AInventory's implementation but can't seem to figure out what's so special about them VS my abstraction.

Why is my AttachToOwner only running once when given many copies of the item?

Note: This is a heavily stripped-down implementation. It's obviously missing a lot more important code but if I didn't strip it down this way, the code would be even more annoying to troubleshoot.
You do not have the required permissions to view the files attached to this post.
Last edited by Nash on Thu Oct 12, 2017 1:10 pm, edited 3 times in total.
User avatar
Rachael
Posts: 13793
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Some trouble with my homebrew Inventory setup.

Post by Rachael »

Nash wrote:Why is my AttachToOwner only running once when given many copies of the item?
Not knowing the full situation here, I can only speak to this specific question.

It's because internally the C++ function that assigns the quantity is using a ".Count += amount" algorithm. It makes absolutely no sense whatsoever to run AttachToOwner 10 times, especially in the cases of health, armor, and ammunition. You aren't actually getting 10 individual items. (As a side, in the case where the player has a copy of the item already, the same thing occurs and the new copy of the item is destroyed - the player only keeps one item with a higher .Count)

What you need is to track what the actual count of the item being given is.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49183
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Some trouble with my homebrew Inventory setup.

Post by Graf Zahl »

If you want to override default behavior you have to override the item's TryPickup method. AttachToOwner just inserts an item into the inventory chain with absolutely no semantics attached to that statement. It is entirely different code which decides in the first place whether an item even needs attaching.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Some trouble with my homebrew Inventory setup.

Post by Nash »

Thanks. Got what I need.

For anyone else who might be interested:

You can use "Amount" to get the count of items given in TryPickup. Here's what my TryPickup looks like:

Code: Select all

    override bool TryPickup(in out Actor toucher)
    {
        while (Amount > 0)
        {
            LADCharacter character = LADCharacter.Find(toucher);
            if (!character) return false;

            character.myItems.Push(self);
            Owner = character;

            BecomeLADItem();

            SortActorInventory(toucher);

            Amount--;
        }

        return true;
    }
 
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Some trouble with my homebrew Inventory setup.

Post by Nash »

Another problem now. Why is it when the item is BecomePickup()'d and spawned into the world, it floats in the air? It's fully interactable (as in my line scans work on it) but it just stays in the air.

What's funny though that in a hub setup, when you re-enter the level, it THEN drops to the floor and resumes normal physics.

EDIT: Solved again. Owner was improperly assigned to my LADItems which for some reason is fucking up the physics code (????).

Return to “Scripting”