The objects/variables are created just before the start label:
Code: Select all
default inventory = []
default selected_item = None
Code: Select all
textbutton "Discard" action Function(discardItem,inventory,selected_item)
#textbutton "Discard" action [RemoveFromSet(inventory,selected_item), SetVariable("selected_item",None)]
And the function itself is in a python init and looks like this:
Code: Select all
def discardItem(inventory,selected_item):
inventory.remove(selected_item)
selected_item = None
I'm not sure if this is something specific to python, which I think it could be from what I've been reading on it, but why does renpy's function work then? And is there some way I could call that function from my python code?
I already tried this (in the python function) and it didn't work, selected_item was still set to the discarded item.
Code: Select all
SetVariable("selected_item",None)
Item selected
And this is what it looks like when the item is discarded/deleted from inventory.
However, "Current Item" section should say "None" like the first image, but it doesn't since selected_item wasn't reset. Which means if the player attempts to discard the item (which no longer exists in inventory) the game will crash.