Getting a different object when clicking a button

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Adrian_DVL
Regular
Posts: 114
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Getting a different object when clicking a button

#1 Post by Adrian_DVL » Tue Aug 31, 2021 9:01 am

Hi!

So I'll try to be quick. I have these functions:

Code: Select all

    class Inventory(renpy.store.object):
        def __init__(self):
            self.items = []
        def add(self, item):
            self.items.append(item)
        def drop(self, item):
            self.items.remove(item)

Code: Select all

    def item_add():
        inventory.add(item)


    def item_drop():
        inventory.drop(item)
And I have this button:

Code: Select all

if buc in inventory.items:
            imagebutton:
                at hp
                idle "sys/fillbuc.png"
                hover "sys/fillbuch.png"
                pos (500, 700)
                action [SetVariable("item", buc), item_drop, SetVariable("item", buw), item_add, Play("sound", "audio/obt.mp3"), Notify(buw.noti)]
Now for some reason, when I click the button, 'buc' is correctly removed from the inventory.items list but, instead of 'buw' being added to it, it is another completely different and not mentioned object the one that's added.

Why is this happening? I can provide some more info if it's neccesary.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Getting a different object when clicking a button

#2 Post by hell_oh_world » Tue Aug 31, 2021 12:23 pm

I don't understand the purpose of your add and drop functions in the class if you will not use those...

Code: Select all

action [Function(inventory.drop, buc), Function(inventory.add, buw), Play("sound", "audio/obt.mp3"), Notify(buw.noti)]

User avatar
Adrian_DVL
Regular
Posts: 114
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Getting a different object when clicking a button

#3 Post by Adrian_DVL » Wed Sep 01, 2021 12:21 pm

hell_oh_world wrote:
Tue Aug 31, 2021 12:23 pm
I don't understand the purpose of your add and drop functions in the class if you will not use those...

Code: Select all

action [Function(inventory.drop, buc), Function(inventory.add, buw), Play("sound", "audio/obt.mp3"), Notify(buw.noti)]
Truth is I didn't think about the Function action haha
Anyway, my problem was not so, since I just had the image files named in a wrong way. Thanks!

Post Reply

Who is online

Users browsing this forum: Google [Bot]