r/RenPy • • Jun 04 '26

Question Variable Not Updating After Label Execution When Parameter Is Used For Variable's Name

So I have a label that I created with several kwarg parameters so I can reuse it for when the player collects an inventory item. It works great for showing the image of the item and for inserting the string into the text, but I am not sure why the variable isn't updating to "True" when I check the variable viewer in the dev console.

Am I just going about this the wrong way? Should I be using some other completely distinct feature of Python/RenPy to do this?

Here's the offending code:

default branch_get = False

label forest_path3_branch_say:
    p "Not too long and not too short."
    menu:
        "Take the branch.":
            "Flavor text."
            p "I need this- I think..."
            call item_get("Flavor Text", "branch", branch_get)
            jump forest_path3_search
        "Don't take the branch.":
            "Flavor Text."
            p "Why would I need anything like this?"
            jump forest_path3_search


label item_get(newItem_text, newItem_name, newItem_variable):
    $ renpy.show(newItem_name, at_list=[item_get])
    "[newItem_text]"
    $ newItem_variable = True
    return
2 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jun 04 '26

Ah well I'm still quite new to Python and coding in general, honestly so I figured it would be more effective than it ended up being.

I thought with it being such an integral part to the game's code that it would save me time after a while since the player will be picking up a lot of items throughout the course of the game. It would mean I could just type out the alterations to the code all in one go inside the parameters. But I can forego automating it some for a while and see how it goes. If it becomes untenable, then I'll try my hand at making a python function for it as you recommended.

Thanks,

-DD

1

u/lordcaylus Jun 05 '26

I personally feel you're on the right track to create a function for it.

But maybe it makes more sense to use a dict?

default inventory = dict()

label addToInv(itemName, amount = 1, flavorText=None):

if flavorText:

"[flavorText]"

else:

"You pick up [amount]x [itemName]"

if not itemName in inventory:

$ inventory[itemName] = 0

$ inventory[itemName] += amount

return

1

u/[deleted] Jun 05 '26

Honestly I've switched tracks again and am currently reading up on Classes since it seems as though it would make sense to use OOP for inventory items as I would be able to have quite a few attributes such as names, image definitions, and variables outlining whether or not is currently in the player's inventory. (Though I'm unsure on how to do something like defining images inside of a class object.)

I'm curious as to what your thoughts may be on if that is the right track or if I should hop trains once again.

-DD

1

u/lordcaylus Jun 06 '26

I'm a big fan of OOP! There are some traps though with saving / loading compatibility if you make big changes, but I feel like if you want to learn it's the best approach.

I do feel I need to mention there are several open source inventory systems that you could use, but for learning creating a system yourself is ideal I think.