Ren'Py itemEat problem

SweetGames

Newbie
Jan 1, 2023
33
4
i have the list edible items

$ Eat = {
"item_spizza": 3,
"item_sandw": 2,
"itemburger": 1

this button

textbutton ("EAT"):
action [ eat_item(selected_item), Function(whichitem.toss, amount), SetVariable("selected_item", None), Hide("buying") ]


stats

init python:
global hunger
hunger_increase = 0
hunger = 10 if 10 >= 0 and 10 <= 100 else 0

def eat_item(item):
global hunger


if item in Eat:
hunger_increase = Eat[item]
hunger = min(100, hunger + hunger_increase)

now it is the case that when i move the mouse over the button it counts up with 1.

the problem i have is that i can't get it to take the items from the list with their values. i tried it with label and just $ hunger but i want the selected item to be eaten. but it just doesn't work
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,231
action [ eat_item(selected_item), Function(whichitem.toss, amount), SetVariable("selected_item", None), Hide("buying") ]
Well, the second entry in your action list give you the answer to your question...

The content of an action list is computed when the screen is proceeded (displayed), reason why most are in fact objects. What is also the reason why you witness such behavior with your code. Therefore, if you want to call a function while passing it parameters, you need to use the Function() screen action.

Two (or was it three) days ago, I gave you the advice to read Ren'Py documentation, you should really give it a try...
 

SweetGames

Newbie
Jan 1, 2023
33
4
thanks but I have solved the problem. Many thanks

now i just have a problem with a screen that disappears but i don't understand why. but tomorrow. thanks