How to make Inventory items Usable for player?
I have a working inventory, and I'm currently trying to figure out how to make it so the player can use the items in their inventory and code it in a way that different items have different effects(attached to variables. Like using food would be $ health += 10, or something to that effect).
*** am able to manually check for an item and remove it myself, but my goal is for the player to be able to use the items in their inventory as needed.***
There are already things I'm able to do, such as checking for inventory items, removing inventory items; I'm just not sure how to associate that into those items effecting variables in the game. What I'm trying to do is make another button that would remove and item and trigger or effect another variable. I feel like this is possible but I just wasn't sure how to make it work, I think I have most of what I need to do it; I just don't know how to put it together.
I'll share what I have for my code, any help, advice or insight is so greatly appreciated!
This is how I check for the item myself and remove it manually in the script:
$ InvItem(*item_sodac).pickup(2)
if inventory.has_item(sodac) == False:
"Nice, I have soda"
$ health += 10
else:
"Damn, I'm so thirsty..."
if "item_sodac" in inv:
$ inv.remove("item_sodac")
else:
pass
This is my how my toss button is written in the script (I want to add a *use* button beside it and connect it to different variables depending on what item is used by the player.
vbox:
align (.9,.1)
style_group "sort"
if selling:
textbutton _("SELL") action ShowTransient("buying", whichitem=thisitem, howmuch=thisitem.value, selling=True)
else:
textbutton _("TOSS") action ShowTransient("buying", whichitem=thisitem, howmuch=0)
# shop-free alternative toss button:
#textbutton _("TOSS") action [Function(thisitem.toss, 1), SetVariable("selected_item", None)]
I can post more/ all of the code but I didn't want the post to look too overwhelming T_T Any insight is much appreciated!