How to display message when player combines items in inventory?

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
asylumsweetie
Regular
Posts: 31
Joined: Sun Mar 31, 2013 2:37 am
Contact:

How to display message when player combines items in inventory?

#1 Post by asylumsweetie »

So I'm using this inventory system and it's working great, but I would like it to display a message whenever the user combines two items (ie: "you glue the spoon to the fork and create a spork!") but I can't figure out a way to do that. I could make the new item appearing in the inventory cause a jump to a new event but then I've got to figure out how to get the player back to the correct place in the story, since they have access to combining items through the whole game. Any ideas?

Code: Select all

######################################Inventory Stuff#################################
init -1 python:
    from operator import attrgetter # we need this for sorting items

    inv_page = 0 # initial page of teh inventory screen
    item = None
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.max_mp=max_mp
            self.mp=max_mp
            self.element=element
    player = Player("MSPAR", 100, 50)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0, recipeItem=False):
            self.selected=False
            self.recipeItem=recipeItem
            self.name = name
            self.player=player # which character can use this item?
            self.hp = hp # does this item restore hp?
            self.mp = mp # does this item restore mp?
            self.element=element # does this item change elemental damage?
            self.image=image # image file to use for this item
            self.cost=cost # how much does it cost in shops?
        def use(self): #here we define what should happen when we use the item
            if self.recipeItem:
                self.selected=not self.selected #item that can be combined with other items
            if self.name=="Palmhusk":
                renpy.call_in_new_context("phonemenu")
            if self.name=="Broken Knife":
                renpy.call_in_new_context("brokenknife")
            if self.hp>0: #healing item
                player.hp = player.hp+self.hp
                if player.hp > player.max_hp: # can't heal beyond max HP
                    player.hp = player.max_hp
                inventory.drop(self) # consumable item - drop after use
            elif self.mp>0: #mp restore item
                player.mp = player.mp+self.mp
                if player.mp > player.max_mp: # can't increase MP beyond max MP
                    player.mp = player.max_mp
                inventory.drop(self) # consumable item - drop after use
            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item

    class Inventory(store.object):
        def __init__(self, money=10):
            self.money = money
            self.items = []
        def add(self, item): # a simple method that adds an item; we could also add conditions here (like check if there is space in the inventory)
            self.items.append(item)
        def drop(self, item):
            self.items.remove(item)
        def buy(self, item):
            if self.money >= item.cost:
                self.items.append(item)
                self.money -= item.cost

    def item_use():
        item.use()

    #Tooltips:
    style.tips_top = Style(style.default)
    #style.title.font="gui/arial.ttf"
    style.tips_top.size=14
    style.tips_top.color="fff"
    style.tips_top.outlines=[(3, "6b7eef", 0,0)]
    style.tips_top.kerning = 5

    style.tips_bottom = Style(style.tips_top)
    style.tips_top.size=20
    style.tips_bottom.outlines=[(0, "6b7eef", 1, 1), (0, "6b7eef", 2, 2)]
    style.tips_bottom.kerning = 2
    
    style.button.background=Frame("gui/frame.png",25,25)
    style.button.yminimum=52
    style.button.xminimum=52
    style.button_text.color="000"


    showitems = True #turn True to debug the inventory
    # def display_items_overlay():
        # if showitems:
            # inventory_show = "Money:" + str(inventory.money) + " HP: " + str(player.hp) + " bullets: " + str(player.mp) + " element: " + str(player.element) + "\nInventory: "
            # for i in range(0, len(inventory.items)):
                # item_name = inventory.items[i].name
                # if i > 0:
                    # inventory_show += ", "
                # inventory_show += item_name
            
            # ui.frame()
            # ui.text(inventory_show, color="#000")
    # config.overlay_functions.append(display_items_overlay)
    
        
screen inventory_button:
    textbutton "Show Inventory" action [ Show("inventory_screen"), Hide("inventory_button")] align (.95,.04)
            
screen inventory_screen:    
    add "gui/inventory.png" # the background
    modal True #prevent clicking on other stuff when inventory is shown
    #use battle_frame(char=player, position=(.97,.20)) # we show characters stats (mp, hp) on the inv. screen
    #use battle_frame(char=dog, position=(.97,.50))
    hbox align (.95,.04) spacing 20:
        textbutton "Close Inventory" action [ Hide("inventory_screen"), Show("inventory_button"), Return(None)]
    $ x = 515 # coordinates of the top left item position
    $ y = 25
    $ i = 0
    $ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first
    $ next_inv_page = inv_page + 1            
    if next_inv_page > int(len(inventory.items)/9):
        $ next_inv_page = 0
    for item in sorted_items:
        if i+1 <= (inv_page+1)*9 and i+1>inv_page*9:
            $ x += 190
            if i%3==0:
                $ y += 170
                $ x = 515
            $ pic = item.image
            $ my_tooltip = "tooltip_inventory_" + pic.replace("gui/inv_", "").replace(".png", "") # we use tooltips to describe what the item does.
            imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), Show("inventory_button"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
            if player.element and (player.element==item.element): #indicate the selected gun
                add "gui/selected.png" xpos x ypos y anchor(.5,.5)
        $ i += 1
        if len(inventory.items)>9:
            textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83
    if item.recipeItem:
                imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
    else:
                imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), Show("inventory_button"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
    if item.selected:
        add "gui/selected.png" xpos x ypos y anchor(.5,.5)
    textbutton "Combine" action [Function(combine_items), Hide("inventory_screen"), Show("inventory_button")] align (.80,.80)
        
screen gui_tooltip (my_picture="", my_tt_xpos=58, my_tt_ypos=687):
    add my_picture xpos my_tt_xpos ypos my_tt_ypos

init -1:
    transform inv_eff: # too lazy to make another version of each item, we just use ATL to make hovered items super bright
        zoom 0.5 xanchor 0.5 yanchor 0.5
        on idle:
            linear 0.2 alpha 1.0
        on hover:
            linear 0.2 alpha 2.5

    image information = Text("INFORMATION", style="tips_top")
    #Tooltips-inventory:
    image tooltip_inventory_mushroom=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A small blue mushroom. Edible?", style="tips_bottom"))
    image tooltip_inventory_husky=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("Your trusty palmhusk!", style="tips_bottom"))
    image tooltip_inventory_moss=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A clump of dry moss", style="tips_bottom"))
    image tooltip_inventory_knife=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A stone knife", style="tips_bottom"))
    image tooltip_inventory_fork=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A stone fork", style="tips_bottom"))
    image tooltip_inventory_spoon=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A stone spoon", style="tips_bottom"))
    image tooltip_inventory_bowl=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A stone bowl", style="tips_bottom"))
    
init python:    
    def combine_items():
        for item in inventory.items:
            for recipe in recipes:
                recipe_tmp = recipe
                if item in recipe and item.selected:
                    recipe_tmp.remove(item)
                    if len(recipe_tmp)==1:
                        for tmp_item in recipe:
                            pass
                            inventory.drop(item)
                        inventory.add(recipe[0])
        return
######################################################################################

    
    # The game starts here.
label start:
    python:
        player = Player("MSPAR", 100, 50)
        player.hp = 50
        player.mp = 10
        mushroom = Item("Mushroom", image="gui/inv_mushroom.png", recipeItem=True)
        moss = Item("Moss", image="gui/inv_moss.png", recipeItem=True)
        husky = Item("Palmhusk", image ="gui/inv_husky.png")
        poison_moss = Item("Poison Moss", image ="gui/inv_pmoss.png", recipeItem=True)
        bowl = Item("Bowl", image ="gui/inv_bowl", recipeItem=True)
        fork = Item("Fork", image ="gui/inv_fork", recipeItem=True)
        spoon = Item("Spoon", image ="gui/inv_spoon", recipeItem=True)
        knife = Item("Knife", image ="gui/inv_knife", recipeItem=True)
        rock = Item("Rock", image ="gui/inv_rock", recipeItem=True)
        piecea = Item("Fragment 1", image ="gui/inv_piecea", recipeItem=True)
        pieceb = Item("Fragment 2", image ="gui/inv_pieceb", recipeItem=True)
        piecec = Item("Fragment 3", image ="gui/inv_piecec", recipeItem=True)
        sticky_piecea = Item("Sticky Fragment 1", image ="gui/inv_pieceas", recipeItem=True)
        sticky_pieceb = Item("Sticky Fragment 2", image ="gui/inv_piecebs", recipeItem=True)
        sticky_piecec = Item("Sticky Fragment 3", image ="gui/inv_piececs", recipeItem=True)
        partial_panel = Item("Two pieces of the broken panel stuck together", image ="gui/inv_partialpanel", recipeItem=True)
        stalactite = Item("Stalactite", image ="gui/stalactite")
        roosterpiece = Item(["Rooster Panel", image ="gui/inv_rooster"])
        horsepiece = Item("Horse Panel", image ="gui/inv_horse")
        snakepiece = Item("Snake Panel", image ="gui/inv_snake")
        moss_bowl = Item("Bowl of Moss", image ="gui/inv_mossbowl", recipeItem=True)
        water_bowl = Item("Bowl of Water", image ="gui/inv_waterbowl")
        sticky_goo = Item("Moss Goo", image ="gui/inv_goo", recipeItem=True)
        poison_goo = Item("Poison Goo", image ="gui/inv_pgoo", recipeItem=True)
        sticky_knife = Item("Sticky Knife", image ="gui/inv_stickyknife", recipeItem=True)
        sticky_fork = Item("Sticky Fork", image ="gui/inv_stickyfork", recipeItem=True)
        sticky_spoon = Item("Sticky Spoon", image ="gui/inv_stickyspoon", recipeItem=True)
        sticky_knifefork = Item("Knork", image ="gui/inv_stickyknifefork", recipeItem=True)
        sticky_knifespoon = Item("Spife", image ="gui/inv_stickyknifespoon", recipeItem=True)
        sticky_forkspoon = Item("Spork", image ="gui/inv_stickyforkspoon", recipeItem=True)
        sticky_knifespoonfork = Item("Sporkife", image ="gui/inv_stickyknifespoonfork", recipeItem=True)
        glowing_knifespoonfork = Item("Glowing Sporkife", image ="gui/inv_glowingknifespoonfork", recipeItem=True)
        poison_knifespoonfork = Item("Poison Sporkife", image ="gui/inv_poisonknifespoonfork", recipeItem=True)
        broken_knife = Item("broken knife")
        broken_fork = Item("broken fork")
        broken_spoon = Item("broken spoon")
        broken_bowl = Item("broken bowl")
        scared_husky = Item("scared husky")
        
        inventory = Inventory()
        recipes = [] 
        recipes.append([poison_moss, moss, mushroom])
        recipes.append([moss_bowl, moss, bowl])
        recipes.append([sticky_goo, moss_bowl, rock])
        recipes.append([poison_goo, sticky_goo, mushroom])
        recipes.append([sticky_knife, sticky_goo, knife])
        recipes.append([sticky_fork, sticky_goo, fork])
        recipes.append([sticky_spoon, sticky_goo, spoon])
        recipes.append([sticky_knifespoon, sticky_knife, sticky_spoon])
        recipes.append([sticky_knifefork, sticky_knife, sticky_fork])
        recipes.append([sticky_forkspoon, sticky_fork, sticky_spoon])
        recipes.append([sticky_knifespoonfork, sticky_knifefork, sticky_spoon])
        recipes.append([sticky_knifespoonfork, sticky_knifespoon, sticky_fork])
        recipes.append([sticky_knifespoonfork, sticky_forkspoon, sticky_knife])
        recipes.append([sticky_knifespoonfork, sticky_knifespoon, fork])
        recipes.append([sticky_knifespoonfork, sticky_knifefork, spoon])
        recipes.append([sticky_knifespoonfork, sticky_forkspoon, knife])
        recipes.append([glowing_knifespoonfork, sticky_knifespoonfork, moss])
        recipes.append([poison_knifespoonfork, sticky_knifespoonfork, poison_moss])
        recipes.append([poison_knifespoonfork, sticky_knifespoonfork, poison_goo])
        recipes.append([glowing_knifespoonfork, poison_knifespoonfork, moss])
        recipes.append([poison_knifespoonfork, glowing_knifespoonfork, poison_moss])
        recipes.append([poison_knifespoonfork, glowing_knifespoonfork, poison_goo])
        recipes.append([sticky_piecea, piecea, sticky_goo])
        recipes.append([sticky_pieceb, pieceb, sticky_goo])
        recipes.append([sticky_piecec, piecec, sticky_goo])
        recipes.append([partial_panel, sticky_piecea, pieceb])
        recipes.append([partial_panel, sticky_piecea, piecec])
        recipes.append([partial_panel, sticky_piecea, sticky_pieceb])
        recipes.append([partial_panel, sticky_piecea, sticky_piecec])
        recipes.append([partial_panel, piecea, sticky_pieceb])
        recipes.append([partial_panel, piecea, sticky_piecec])
        recipes.append([partial_panel, sticky_pieceb, piecec])
        recipes.append([partial_panel, pieceb, sticky_piecec])
        ###bad recipes###
        recipes.append([broken_knife, rock, knife])
        recipes.append([broken_fork, rock, fork])
        recipes.append([broken_spoon, rock, spoon])
        recipes.append([broken_bowl, rock, bowl])
        recipes.append([scared_husky, rock, husky])
        
        #add items to the initial inventory:
        inventory.add(husky)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2405
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to display message when player combines items in inventory?

#2 Post by Ocelot »

asylumsweetie wrote: Fri Jul 09, 2021 6:57 pm I could make the new item appearing in the inventory cause a jump to a new event but then I've got to figure out how to get the player back to the correct place in the story
You can call correct place instead, as call is made to jump to arbitrary place and then return back where you were. Or you can use renpy.notify() to display a notification.
< < insert Rick Cook quote here > >

asylumsweetie
Regular
Posts: 31
Joined: Sun Mar 31, 2013 2:37 am
Contact:

Re: How to display message when player combines items in inventory?

#3 Post by asylumsweetie »

I'll try the notify thing tomorrow, but so far using call and return isn't returning me to the right places. It's not even returning me to the same place every time I use it? It's very frustrating lol.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: How to display message when player combines items in inventory?

#4 Post by hell_oh_world »

Correct me if I'm wrong if this function...

Code: Select all

init python:    
    def combine_items():
      ...
      return
is the one that does the combination of items, then you can just simply put renpy.notify right after/before adding the combined item to your inventory.

Code: Select all

init python:    
    def combine_items():
        for item in inventory.items:
            for recipe in recipes:
                recipe_tmp = recipe
                if item in recipe and item.selected:
                    recipe_tmp.remove(item)
                    if len(recipe_tmp)==1:
                        for tmp_item in recipe:
                            pass
                            inventory.drop(item)
                        inventory.add(recipe[0])
                        renpy.notify("You got '{}'".format(recipe[0].name)) # I'm guessing the code above this line is the combined item...
        return

asylumsweetie
Regular
Posts: 31
Joined: Sun Mar 31, 2013 2:37 am
Contact:

Re: How to display message when player combines items in inventory?

#5 Post by asylumsweetie »

Unfortunately got a "Recipe object does not support indexing" error when I tried that. I might have just put it in the wrong place though. I ended up changing that section of code and restructuring how the recipes are defined to fix a different issue.

Code: Select all

init -1 python:
    import copy
    from operator import attrgetter # we need this for sorting items

    inv_page = 0 # initial page of teh inventory screen
    item = None
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.max_mp=max_mp
            self.mp=max_mp
            self.element=element
    player = Player("MSPAR", 100, 50)
    
    class Recipe(store.object):
        def __init__(self, items=[], item_created=None):
            self.items = items
            self.item_created = item_created
        def combine_check(self):
            too_many=False # too many items selected?
            correct_recipe_items = copy.copy(self.items) # make a copy of the list of recipe items
            for item in inventory.selected_items:
                if item.recipeItem: # and item in self.items:
                    if item in correct_recipe_items:
                        correct_recipe_items.remove(item) # remove the current item from the list of correct_recipe_items; if correct_recipe_items is empty at the end, we have created the recipe
                    if not (item in self.items): # current item is not in this recipe
                        too_many=True
            if len(correct_recipe_items) == 0 and not too_many: # correct_recipe_items is empty means we have selecte just the right items
                inventory.add(self.item_created) # add the newly created item
                for drop_item in self.items: # remove all the items in this recipe from inventory
                    inventory.drop(drop_item)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0, recipeItem=False):
            self.selected=False
            self.recipeItem=recipeItem
            self.name = name
            self.player=player # which character can use this item?
            self.hp = hp # does this item restore hp?
            self.mp = mp # does this item restore mp?
            self.element=element # does this item change elemental damage?
            self.image=image # image file to use for this item
            self.cost=cost # how much does it cost in shops?
        def use(self): #here we define what should happen when we use the item
            if self.recipeItem:
                if self in inventory.selected_items:
                    inventory.selected_items.remove(self)
                else:
                    inventory.selected_items.append(self)
            if self.name=="Palmhusk":
                renpy.call_in_new_context("phonemenu")
            if self.name=="Broken Knife":
                renpy.call_in_new_context("brokenknife")
            if self.hp>0: #healing item
                player.hp = player.hp+self.hp
                if player.hp > player.max_hp: # can't heal beyond max HP
                    player.hp = player.max_hp
                inventory.drop(self) # consumable item - drop after use
            elif self.mp>0: #mp restore item
                player.mp = player.mp+self.mp
                if player.mp > player.max_mp: # can't increase MP beyond max MP
                    player.mp = player.max_mp
                inventory.drop(self) # consumable item - drop after use
            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item

    class Inventory(store.object):
        def __init__(self):
            self.items = []
            self.selected_items = []
        def add(self, item): # a simple method that adds an item; we could also add conditions here (like check if there is space in the inventory)
            self.items.append(item)
        def drop(self, item):
            self.items.remove(item)
        def buy(self, item):
            if self.money >= item.cost:
                self.items.append(item)
                self.money -= item.cost

    def item_use():
        item.use()

    #Tooltips:
    style.tips_top = Style(style.default)
    #style.title.font="gui/arial.ttf"
    style.tips_top.size=14
    style.tips_top.color="fff"
    style.tips_top.outlines=[(3, "6b7eef", 0,0)]
    style.tips_top.kerning = 5

    style.tips_bottom = Style(style.tips_top)
    style.tips_top.size=20
    style.tips_bottom.outlines=[(0, "6b7eef", 1, 1), (0, "6b7eef", 2, 2)]
    style.tips_bottom.kerning = 2
    
    style.button.background=Frame("gui/frame.png",25,25)
    style.button.yminimum=52
    style.button.xminimum=52
    style.button_text.color="000"


    showitems = True #turn True to debug the inventory
    # def display_items_overlay():
        # if showitems:
            # inventory_show = "Money:" + str(inventory.money) + " HP: " + str(player.hp) + " bullets: " + str(player.mp) + " element: " + str(player.element) + "\nInventory: "
            # for i in range(0, len(inventory.items)):
                # item_name = inventory.items[i].name
                # if i > 0:
                    # inventory_show += ", "
                # inventory_show += item_name
            
            # ui.frame()
            # ui.text(inventory_show, color="#000")
    # config.overlay_functions.append(display_items_overlay)
    
        
screen inventory_button:
    textbutton "Show Inventory" action [ Show("inventory_screen"), Hide("inventory_button")] align (.95,.04)
            
screen inventory_screen:    
    add "gui/inventory.png" # the background
    modal True #prevent clicking on other stuff when inventory is shown
    #use battle_frame(char=player, position=(.97,.20)) # we show characters stats (mp, hp) on the inv. screen
    #use battle_frame(char=dog, position=(.97,.50))
    hbox align (.75,.04) spacing 20:
        textbutton "Close Inventory" action [ Hide("inventory_screen"), Show("inventory_button")]
    $ x = 515 # coordinates of the top left item position
    $ y = 25
    $ i = 0
    $ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True) # we sort the items, so non-consumable items that change elemental damage (guns) are listed first
    $ sorted_items = sorted(inventory.items, key=attrgetter('name')) #sort by name
    $ next_inv_page = inv_page + 1
    $ prev_inv_page = inv_page -1 #my code
    if next_inv_page > int(len(inventory.items)/9):
        $ next_inv_page = 0
    if prev_inv_page < int(len(inventory.items)/9): #my code 
        $ prev_inv_page = 0
    if next_inv_page < int(len(inventory.items)/9):
        $ next_inv_page = 1
        
    $ tmp_inventory = []
    for item in sorted_items:
        $ tmp_inventory.append(item)
        if tmp_inventory.count(item) == 1:
            if i+1 <= (inv_page+1)*9 and i+1>inv_page*9:
                $ x += 190
                if i%3==0:
                    $ y += 170
                    $ x = 515
                $ pic = item.image
                $ my_tooltip = "tooltip_inventory_" + pic.replace("gui/inv_", "").replace(".png", "") # we use tooltips to describe what the item does.
                if item.recipeItem:
                    imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
                else:
                    imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), Show("inventory_button"), SetVariable("item", item), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
                if item in inventory.selected_items:
                    add "gui/selected.png" xpos x ypos y anchor(.5,.5)                        
                $ i += 1
            if sorted_items.count(item) > 1:
                text str(sorted_items.count(item)) xpos x+50 ypos y-50 anchor(.5,.5) color "#000" #align(.9,.1)    if item.recipeItem:
        if len(inventory.items)>9:
            textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83
            textbutton _("Prev Page") action [SetVariable('inv_page', prev_inv_page), Show("inventory_screen")] xpos .575 ypos .83
    textbutton "Combine" action [Function(combine_items), Hide("inventory_screen"), Show("inventory_button")] align (.70,.89)
    if item.selected:
        add "gui/selected.png" xpos x ypos y anchor(.5,.5)
    
screen gui_tooltip (my_picture="", my_tt_xpos=58, my_tt_ypos=687):
    add my_picture xpos my_tt_xpos ypos my_tt_ypos

init -1:
    transform inv_eff:
        zoom 0.5 xanchor 0.5 yanchor 0.5
        on idle:
            linear 0.2 alpha 1.0
        on hover:
            linear 0.2 alpha 2.5
        on selected_idle:
            linear 0.2 alpha 1.0
        on selected_hover:
            linear 0.2 alpha 2.5
            
    image information = Text("INFORMATION", style="tips_top")
    #Tooltips-inventory:
    image tooltip_inventory_mushroom=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A small blue mushroom. Edible?", style="tips_bottom"))
    image tooltip_inventory_husky=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("Your trusty palmhusk!", style="tips_bottom"))
    image tooltip_inventory_moss=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A clump of dry moss", style="tips_bottom"))
    image tooltip_inventory_knife=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A stone knife", style="tips_bottom"))
    image tooltip_inventory_fork=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A stone fork", style="tips_bottom"))
    image tooltip_inventory_spoon=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A stone spoon", style="tips_bottom"))
    image tooltip_inventory_bowl=LiveComposite((665, 73), (3,-30), ImageReference("information"), (3,0), Text("A stone bowl", style="tips_bottom"))
    
init python:    
    def combine_items():
        for recipe in recipes:
            recipe.combine_check()
        inventory.selected_items = []
        renpy.notify("You got '{}'".format(recipe[0].name))
        return
######################################################################################

    
    # The game starts here.
label start:
    python:
        player = Player("MSPAR", 100, 50)
        player.hp = 50
        player.mp = 10
        mushroom = Item("Mushroom", image="gui/inv_mushroom_idle.png", recipeItem=True)
        moss = Item("Moss", image="gui/inv_moss_idle.png", recipeItem=True)
        husky = Item("Palmhusk", image="gui/inv_husky_idle.png")
        poison_moss = Item("Poison Moss", image="gui/inv_pmoss_idle.png", recipeItem=True)
        bowl = Item("Bowl", image="gui/inv_bowl_idle.png", recipeItem=True)
        fork = Item("Fork", image="gui/inv_fork_idle.png", recipeItem=True)
        spoon = Item("Spoon", image="gui/inv_spoon_idle.png", recipeItem=True)
        knife = Item("Knife", image="gui/inv_knife_idle.png", recipeItem=True)
        rock = Item("Rock", image="gui/inv_rock_idle.png", recipeItem=True)
        piecea = Item("Fragment 1", image="gui/inv_piecea_idle.png", recipeItem=True)
        pieceb = Item("Fragment 2", image="gui/inv_pieceb_idle.png", recipeItem=True)
        piecec = Item("Fragment 3", image="gui/inv_piecec_idle.png", recipeItem=True)
        sticky_piecea = Item("Sticky Fragment 1", image="gui/inv_pieceas_idle.png", recipeItem=True)
        sticky_pieceb = Item("Sticky Fragment 2", image="gui/inv_piecebs_idle.png", recipeItem=True)
        sticky_piecec = Item("Sticky Fragment 3", image="gui/inv_piececs_idle.png", recipeItem=True)
        partial_panel = Item("Two pieces of the broken panel stuck together", image="gui/inv_partialpanel_idle.png", recipeItem=True)
        stalactite = Item("Stalactite", image="gui/inv_stalactite_idle.png")
        roosterpiece = Item("Rooster Panel", image="gui/inv_rooster_idle.png")
        horsepiece = Item("Horse Panel", image="gui/inv_horse_idle.png")
        snakepiece = Item("Snake Panel", image="gui/inv_snake_idle.png")
        moss_bowl = Item("Bowl of Moss", image="gui/inv_mossbowl_idle.png", recipeItem=True)
        water_bowl = Item("Bowl of Water", image="gui/inv_waterbowl_idle.png")
        sticky_goo = Item("Moss Goo", image="gui/inv_goo_idle.png", recipeItem=True)
        poison_goo = Item("Poison Goo", image="gui/inv_pgoo_idle.png", recipeItem=True)
        sticky_knife = Item("Sticky Knife", image="gui/inv_stickyknife_idle.png", recipeItem=True)
        sticky_fork = Item("Sticky Fork", image="gui/inv_stickyfork_idle.png", recipeItem=True)
        sticky_spoon = Item("Sticky Spoon", image="gui/inv_stickyspoon_idle.png", recipeItem=True)
        sticky_knifefork = Item("Knork", image="gui/inv_stickyknifefork_idle.png", recipeItem=True)
        sticky_knifespoon = Item("Spife", image="gui/inv_stickyknifespoon_idle.png", recipeItem=True)
        sticky_forkspoon = Item("Spork", image="gui/inv_stickyforkspoon_idle.png", recipeItem=True)
        sticky_knifespoonfork = Item("Sporkife", image="gui/inv_stickyknifespoonfork_idle.png", recipeItem=True)
        glowing_knifespoonfork = Item("Glowing Sporkife", image="gui/inv_glowingknifespoonfork_idle.png", recipeItem=True)
        poison_knifespoonfork = Item("Poison Sporkife", image="gui/inv_poisonknifespoonfork_idle.png", recipeItem=True)
        broken_knife = Item("broken knife")
        broken_fork = Item("broken fork")
        broken_spoon = Item("broken spoon")
        broken_bowl = Item("broken bowl")
        scared_husky = Item("scared husky")
        
        inventory = Inventory()
        recipes = [Recipe([moss,mushroom], poison_moss), 
            Recipe([moss,bowl], moss_bowl), 
            Recipe([moss_bowl,rock], sticky_goo), 
            Recipe([sticky_goo,mushroom], poison_goo),
            Recipe([sticky_goo,knife], sticky_knife), 
            Recipe([sticky_goo,fork], sticky_fork), 
            Recipe([sticky_goo,spoon], sticky_spoon), 
            Recipe([sticky_knife,sticky_spoon], sticky_knifespoon),
            Recipe([sticky_knife,sticky_fork], sticky_knifefork), 
            Recipe([sticky_fork,sticky_spoon], sticky_forkspoon),
            Recipe([sticky_knifefork,sticky_spoon], sticky_knifespoonfork), 
            Recipe([sticky_knifespoon,sticky_fork], sticky_knifespoonfork),
            Recipe([sticky_forkspoon,sticky_knife], sticky_knifespoonfork), 
            Recipe([sticky_knifespoon,fork], sticky_knifespoonfork), 
            Recipe([sticky_knifefork,spoon], sticky_knifespoonfork), 
            Recipe([sticky_forkspoon,knife], sticky_knifespoonfork), 
            Recipe([sticky_knifespoonfork,moss], glowing_knifespoonfork), 
            Recipe([sticky_knifespoonfork,poison_moss], poison_knifespoonfork), 
            Recipe([sticky_knifespoonfork,poison_goo], poison_knifespoonfork), 
            Recipe([poison_knifespoonfork,moss], glowing_knifespoonfork), 
            Recipe([glowing_knifespoonfork,poison_moss], poison_knifespoonfork), 
            Recipe([glowing_knifespoonfork,poison_goo], poison_knifespoonfork),
            Recipe([piecea,sticky_goo], sticky_piecea),
            Recipe([pieceb,sticky_goo], sticky_pieceb),
            Recipe([piecec,sticky_goo], sticky_piecec),
            Recipe([sticky_piecea,pieceb], partial_panel),
            Recipe([sticky_piecea,piecec], partial_panel),
            Recipe([sticky_piecea,sticky_pieceb], partial_panel),
            Recipe([sticky_piecea,sticky_piecec], partial_panel),
            Recipe([piecea,sticky_pieceb], partial_panel),
            Recipe([piecea,sticky_piecec], partial_panel),
            Recipe([pieceb,sticky_piecec], partial_panel),
            Recipe([sticky_pieceb,piecec], partial_panel),
            Recipe([rock,knife], broken_knife),
            Recipe([rock,fork], broken_fork),
            Recipe([rock,spoon], broken_spoon),
            Recipe([rock,bowl], broken_bowl),
            Recipe([rock,husky], scared_husky),
            ]
        
        #add items to the initial inventory:
        inventory.add(husky)


User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: How to display message when player combines items in inventory?

#6 Post by hell_oh_world »

Looks like you already know well enough with this new logic of the code.
In this part of the code...

Code: Select all

def combine_check(self):
            too_many=False # too many items selected?
            correct_recipe_items = copy.copy(self.items) # make a copy of the list of recipe items
            for item in inventory.selected_items:
                if item.recipeItem: # and item in self.items:
                    if item in correct_recipe_items:
                        correct_recipe_items.remove(item) # remove the current item from the list of correct_recipe_items; if correct_recipe_items is empty at the end, we have created the recipe
                    if not (item in self.items): # current item is not in this recipe
                        too_many=True
            if len(correct_recipe_items) == 0 and not too_many: # correct_recipe_items is empty means we have selecte just the right items
                inventory.add(self.item_created) # add the newly created item
                for drop_item in self.items: # remove all the items in this recipe from inventory
                    inventory.drop(drop_item)
Specifically, this part...

Code: Select all

inventory.add(self.item_created) # add the newly created item
you can just put the notification here. most likely as renpy.notify(self.item_created.name)

Post Reply

Who is online

Users browsing this forum: No registered users