Ren'Py User-defined class method as an action renpy(Solved)

Somatra

Member
Game Developer
Mar 15, 2021
458
575
i have a problem but i don't find how to fix

i have my class :

class Food(object):
def __init__(self,name,hgy,val,amount,ID):
self.name = name
self.hungry = hgy
self.val = val
self.amount = amount
self.ID = ID

def ConsumeFood(self):
self.amount -= 1
persistent.Food += self.hgy
if persistent.Food >= 10:
persistent.Food == 10


and i have a screen x

screen x:
showif inventory == True:
showif [inventory[3]].amount >= 1: Only will be display in inventory if the item exist
text"Amount: [inventory[3]].amount]": Show the amount of that item
xpos: whatever
ypos: whatever
textbutton "consume food":
action Function([inventory[3].ConsumeFood())
xpos: whatever
ypos: whatever


everthing works fine but the textbutton consume food works more than i want
as soon as you receive any food item it is automatically consumed
the button does not even appear but it is visible that it works because the amount of food increases.

anyone know how i can fix this ? I want the user to consume the food only when he clicks
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,363
15,277
edit: i find a solution thanks :)
You know, there's nothing more frustrating when you're facing a problem yourself, than to find this kind of content.
It's good that you found the solution by yourself, but the reader who will come to this thread in the future, because he encounter the same error, would be happy to know what this solution is.

Therefore, for you reader from the future, the problem came from this line :
Code:
        action Function([inventory[3].ConsumeFood())
[Assuming that the [ before "inventory" is a typo when presenting the code here.]

The Function screen action expect the name of a function as parameter, while he provided the result of this function. He should have wrote inventory[3].ConsumeFood and not use the trailing ().

To go further, you can read this post regarding the meaning of () and why it was an error here.