Ren'Py Creating Individual "Items", am I doing this wrong?

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
In summary, I'd like to be able to create a totally new instance of a potion and place it in the player's inventory without it affecting other items of the same name.
Without code it's near to impossible to answer, because no one except you know what you are doing wrong.

So, the easiest is probably to show you how to do it right:
Python:
init python:
    class Items( renpy.python.RevertableObject ):
        def __init__( self, trait1, trait2, trait3, trait4 ):
            self.trait1 = trait1
            self.trait2 = trait2
            self.trait3 = trait3
            self.trait4 = trait4

    class Potion( renpy.python.RevertableObject ):
        def __init__( self, trait1, trait2, trait3, trait4 ):
            self.trait1 = trait1
            self.trait2 = trait2
            self.trait3 = trait3
            self.trait4 = trait4

    def preparePotion( item1, item2 ):
        return Potion( item1.trait1 + item2.trait1, item1.trait2 + item2.trait2, item1.trait3 + item2.trait3, item1.trait4 + item2.trait4 )

default toadSlime = Item( 1, 1, 1, 2 )
default batBlood = Item( 2, 1, 2, 1 )
default inventory = []

label whatever:
    "You're mixing toad slime with bat blood"
    $ createdPotion = preparePotion( toadSlime, batBlood )
    "You now have a new potion in your inventory"
    $ inventory.append( createdPotion )
Of course, the objects need more attributes than just the four traits (name, ID, etc.), and the creation can be done otherwise than by adding the traits of the components (median value, maximal value, minimal value, etc.). But I focused on the problem you have, so goes to the simplest possible code.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
Looking at your example, I don't see anything I have done wrong.
And like you're the only one to know what you've done, or even if it's effectively the object assignation that is wrong and not the way you store them or display them.


Is it possible that the program is confusing items of the same exact name?
Er... What do you mean by "same exact name" ?
 

Jman9

Engaged Member
Jul 17, 2019
2,295
961
Probably an issue with mutable objects and/or Python's way of doing pointers. Hard to say without seeing actual code, though.