Inventory Screen

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Inventory Screen

#61 Post by noeinan »

I had thought for sure I had posted directly in this thread, but I must be remembering a different one or a pm! Commenting to be sure I get updates, this is great code leon. :3
Image

Image
Image

Kasa
Newbie
Posts: 1
Joined: Fri Jan 13, 2017 11:56 pm
Contact:

Re: Inventory Screen

#62 Post by Kasa »

Hi! I'm currently prototyping my second Ren'py game and decided to try adding an inventory system. I downloaded and adapted leon's script to fit my prototype, but have continuously run into a major problem: save files don't remember what items are in the inventory. Instead, they only show which items were in the inventory right before a save was loaded (if a save is loaded from the main menu after launching the game, the inventory is empty). For reference, I'm using Ren'py 6.99.12.2.2029.

Here's what I have written in the script file:

Code: Select all

init -1 python:
 import renpy.store as store
 import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
 from operator import attrgetter # we need this for sorting items

 inv_page = 0 # initial page of teh inventory screen
 item = None
    
 class Item(store.object):
  def __init__(self, name, keyitem="", image=""):
   self.name = name
   self.keyitem=keyitem
   self.image=image # image file to use for this item
  def use(self): #here we define what should happen when we use the item
   if self.name=="Treasure Map": 
    renpy.jump("items_event5")
   if self.name=="Guidebook":
    renpy.jump("items_event5")
   if self.name=="Sneakers":
    renpy.jump("items_event4")

 class Inventory(store.object):
  def __init__(self):
   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)
   if item in self.items: # this if/else statement places a limit of one of each item in the inventory
    return True
   else:
    self.items.append(item)
  def drop(self, item):
   self.items.remove(item)
 def item_use():
  item.use()

[style.tips and style.buttons are unchanged]

[screen inventory_button is unchanged]

screen inventory_screen:    
 add "gui/inventory.png" # the background
 modal True # prevent clicking on other stuff when inventory is shown
 zorder 1
 hbox align (.95,.04) spacing 20:
  textbutton "Close Inventory" action [ Hide("inventory_screen"), Show("inventory_button")]
 $ x = 20 # coordinates of the top left item position
 $ y = 26
 $ i = 0
 $ sorted_items = sorted(inventory.items, key=attrgetter('keyitem'), reverse=True)
 $ 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 += 100 # coordinates of additional items in first row
   if i%9==0:
    $ y += 72 # initial coordinates of first item - vert.
    $ x = 92 # initial coordinates of first item - horiz.
   $ pic = item.image
   $ my_tooltip = "tooltip_inventory_" + pic.replace("images/other/item_", "").replace(".png", "") 
   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", "sound/sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
  $ i += 1
  if len(inventory.items)>9:
   textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83

[rest is largely unchanged]
And here's what's after label start:

Code: Select all

scene bg beach
    
 show ps neu
 show screen inventory_button
 ps "Click on the inventory button. The inventory should be empty."
 ps "Are you done?"
 ps "Click on the sneakers on the next screen to add it to your inventory."
 hide ps neu
 
label items_event:

 window hide None
 call screen beachsearch
 window show None

 if _return == "gettreasuremap": 
  menu:
   "Do you want to pick up the treasure map?"
   "Yes":
    $inventory.add(treasuremap)
    jump items_event
   "No, I want to pick something else":
    jump items_event
   "No, I'm done":
    jump items_event2
    
 if _return == "getguidebook": 
  menu:
   "Do you want to pick up the guide book?"
   "Yes":
    $inventory.add(guidebook)
    jump items_event
   "No, I want to pick something else":
    jump items_event
   "No, I'm done":
    jump items_event2
    
 if _return == "getsneakers": 
  menu:
   "Do you want to pick up the sneakers?"
   "Yes":
     $inventory.add(sneakers)
     jump items_event
   "No, I want to pick something else":
    jump items_event
   "No, I'm done":
    jump items_event2

label items_event2:

 hide screen beachsearch
 show ps gri
 ps "Well, is it there? Check the inventory and see!"
 show ps grisne
 ps "Great! Now, can you give me the sneakers?"
 
label items_event3:
 
 window hide None
 call screen inventory_screen
  
 if Item.use(sneakers):
  jump items_event4
 elif Item.use(treasuremap):
  jump items_event5
 elif item.use(guidebook):
  jump items_event5
 else:
  jump items_event5
        
label items_event4:
 
 if renpy.showing("ps grisne"):
  window show None
  $inventory.drop(sneakers)
  "You gave the sneakers to [ps]."
  ps "Great, thank you!"
  jump wrapitup
 else:
  "You can't use that here."
  $renpy.rollback(force=True, checkpoints=1, defer=False, greedy=True, label=None, abnormal=True)

label items_event5:

 if renpy.showing("ps grisne"):
  ps "This... isn't what I wanted..."
  ps "Can you please give me the sneakers?"
  jump items_event3
 else:
  "You can't use that here."
  $renpy.rollback(force=True, checkpoints=1, defer=False, greedy=True, label=None, abnormal=True)
 
# This ends the game.

label wrapitup:

 show ps gri
 ps "You will now return to the main menu. The end!"
 return
I've been poring over the code trying to see what I'm missing, but haven't had any luck so far. I'm still fairly new to Python as well, so any help is appreciated! Thanks in advance!

ETA: Have tried out a couple of things since I posted.

First off, this same problem seems to occur in leon's main inventory script when it's left untouched. To trigger it, consume all the items in the inventory before getting the gun, and then save. Loading the save should refill the inventory with the consumed items.

I did notice, however, that leaving one item in the inventory will cause the game to save properly, so I tried adding an item to my own game, right after "label start", that couldn't be dropped. Unfortunately, this didn't work, and sometimes, a loaded save would have a completely blank inventory, without even the newly added item.

ETA #2: Figured it out!

Before, I had the items sorted out like this:

Code: Select all

## ----- ITEMS -----

define inventory = Inventory()

define startingitem = Item("Starter", keyitem="starter", image="images/other/item_startingitem.png") 

define treasuremap = Item("Treasure Map", image="images/other/item_map.png")
define guidebook = Item("Guidebook", image="images/other/item_guide.png")
define sneakers = Item("Sneakers", image="images/other/item_sneakers.png")

##  The game starts here. 

label start:
 
 $inventory.add(startingitem)
 
 scene bg beach
    
 show ps neu
 show screen inventory_button
 ps "Click on the inventory button. The inventory should be empty."
 ps "Are you done?"
 ps "Click on the sneakers on the next screen to add it to your inventory."
 hide ps neu
...but now it seems like the items must be listed after label start in order for the inventory to work and be saveable:

Code: Select all

## ----- ITEMS -----

#define inventory = Inventory()

#define startingitem = Item("Starter", keyitem="starter", image="images/other/item_startingitem.png") 

#define treasuremap = Item("Treasure Map", image="images/other/item_map.png")
#define guidebook = Item("Guidebook", image="images/other/item_guide.png")
#define sneakers = Item("Sneakers", image="images/other/item_sneakers.png")

## The game starts here.

label start:
 
 python:
  inventory = Inventory()
  startingitem = Item("Starter", keyitem="starter", image="images/other/item_startingitem.png") 
  treasuremap = Item("Treasure Map", image="images/other/item_map.png")
  guidebook = Item("Guidebook", image="images/other/item_guide.png")
  sneakers = Item("Sneakers", image="images/other/item_sneakers.png")
  inventory.add(startingitem)
 
 scene bg beach
    
 show ps neu
 show screen inventory_button
 ps "Click on the inventory button. The inventory should be empty."
 ps "Are you done?"
 ps "Click on the sneakers on the next screen to add it to your inventory."
 hide ps neu
Sorry for any trouble, but I hope this helps someone else out in the future ^^; In short, there must be at least one item in the inventory at all times (this could be a key item, an invisible item, etc.) in order for said inventory to save properly, and all the items must be defined after label start.

chrysagon
Newbie
Posts: 3
Joined: Tue Jan 31, 2017 1:38 pm
Location: France
Contact:

Re: Inventory Screen

#63 Post by chrysagon »

Thanks for the great job ! That was what I was loking for.
I am trying to add another type of item into the inventory : different types of armor that the player will find during the game. It is also a not a consumable item. so I added code like this :

Code: Select all

    inv_page = 0 # initial page of the inventory screen
    item = None
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None, armor=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
            self.armor=armor
I also dupplicated code everywhere, matching the settings of the 'element' parameter. And it almost works.
But I have a few problems : it seems I can't have at the same time some information into 'element' and into 'armor'. Each time the player chooses one into the inventory, it seems to empty the other. Plus, I can't make the 'selected' word appear on a weapon (element) and an armor (armor), probably for the same reasons.
Could you please help me ?

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Inventory Screen

#64 Post by noeinan »

chrysagon wrote:Thanks for the great job ! That was what I was loking for.
Happy I could help!
chrysagon wrote:I am trying to add another type of item into the inventory : different types of armor that the player will find during the game. It is also a not a consumable item. I also dupplicated code everywhere, matching the settings of the 'element' parameter. And it almost works.
But I have a few problems : it seems I can't have at the same time some information into 'element' and into 'armor'. Each time the player chooses one into the inventory, it seems to empty the other. Plus, I can't make the 'selected' word appear on a weapon (element) and an armor (armor), probably for the same reasons.
Could you please help me ?
Hm, I'm not totally sure I understand the problem... Could you perhaps post some screenshots showing what you mean? (Ex. a screenshot of what the inventory looks like, along with code showing what items should be in the inventory, and the 'selected' word thing. Do you mean the tooltip?)
Image

Image
Image

chrysagon
Newbie
Posts: 3
Joined: Tue Jan 31, 2017 1:38 pm
Location: France
Contact:

Re: Inventory Screen

#65 Post by chrysagon »

The tooltips are working fine. Here are a few screenshots. My goal is to make possible for the player to select a weapon and an armor.

Here is the screen right after we choose the weapon (I used a text test line to show what's in the element variable and in the armor variable ; epee in french means sword). There is nothing in Armor, and the sword appears "selected" in the inventory.
Image

After clicking on an armor, the Armor variable is updated and the corresponding icon appears selected, but the weapon (element) is not anymore and the corresponding variable is now empty.
Image


Here's the big part of the code :

Code: Select all

init -1 python:
    import renpy.store as store
    import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
    from operator import attrgetter # we need this for sorting items

    inv_page = 0 # initial page of the inventory screen
    item = None
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None, armure=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
            self.armure=armure
    player = Player("Derp", 100, 50)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", armure="", image="", cost=0):
            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.armure=armure # classe d'armure
            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.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
                player.armure=self.armure #item to change armor; 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 (.55,.05) spacing 40: #position du bouton "FERMER" Text("Épée courte.", style="tips_top")) style style.button["Foo"]
        textbutton "FERMER" action [ Hide("inventory_screen")]
    $ x = 515 # coordinates of the top left item position (515 et 25)
    $ 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"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "audio/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)
            if player.armure and (player.armure==item.armure): #indicate the selected armor
                add "gui/selected.png" xpos x ypos y anchor(.5,.5)
        $ i += 1
        if len(inventory.items)>9:
            textbutton _("SUITE") action [SetVariable('inv_page', next_inv_page), Show("inventory_screen")] xpos .475 ypos .83

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(" ", style="tips_top")
    #Tooltips-inventory:
    #image tooltip_inventory_chocolate=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("Generic chocolate to heal\n40 points of health.", style="tips_bottom"))
    #image tooltip_inventory_banana=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A healthy banana full of potassium! You can also use it as ammo for your guns! O.O Recharges 20 bullets.", style="tips_bottom"))
    #image tooltip_inventory_gun=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("An gun that looks like something a cop would\ncarry around. Most effective on humans.", style="tips_bottom"))
    #image tooltip_inventory_laser=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("An energy gun that shoots photon beams.\nMost effective on aliens.", style="tips_bottom"))
    image tooltip_inventory_epee=LiveComposite((665, 73), (3,0), ImageReference("information"), (0,-25), Text("Épée courte", style="tips_top"))
    image tooltip_inventory_acuir=LiveComposite((665, 73), (3,0), ImageReference("information"), (0,-25), Text("Armure de Cuir", style="tips_top"))
    image tooltip_inventory_clout=LiveComposite((665, 73), (3,0), ImageReference("information"), (0,-25), Text("Armure de Cuir Clouté", style="tips_top"))
    image tooltip_inventory_potion=LiveComposite((665, 73), (3,0), ImageReference("information"), (0,-25), Text("Potion de guérison, restaure jusqu'à 10 pv.", style="tips_top"))
And the item details :

Code: Select all

        potion = Item("Potion", hp=10, image="gui/inv_potion.png")
        epee = Item("Épée", element="epee", image="gui/inv_epee.png")
        acuir = Item("Armure Cuir", armure="acuir", image="gui/inv_acuir.png")
        clout = Item("Armure de Cuir Clouté", armure="clout", image="gui/inv_clout.png")

User avatar
Pomeranian
Regular
Posts: 33
Joined: Wed Oct 12, 2016 6:52 pm
Contact:

Re: Inventory Screen

#66 Post by Pomeranian »

Code: Select all

            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item
                player.armure=self.armure #item to change armor; we don't drop it, since it's not a consumable item

I'd suggest making these two seperate elifs rather than being together! I think what's happening is that when you equip the sword it goes to the element and because it's blank on the sword it changes the player.element to nothing

User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Re: Inventory Screen

#67 Post by noeinan »

Hmmmm, I'm not an expert by any stretch of the imagination, but I have some ideas about where this problem might come from? First, there might be a place in the code that makes sure only *one* item is selected at a given time. Second, I know "elements" was originally meant to deal with elemental damage and that might be causing some problems unless your re-wrote it? (Though, looking at your code snippet, nothing stands out to me.)
Image

Image
Image

User avatar
Discostar
Regular
Posts: 40
Joined: Mon Mar 10, 2014 10:29 am
Contact:

Re: Inventory Screen

#68 Post by Discostar »

Item definitions never work for me.

Here is my code:

Code: Select all

label start:
      python:
           box = Item("box", image="img/items/box.png")

      $ inventory.add(box)

I get the error that "box" is not defined:

Code: Select all

While running game code:
  File "game/script.rpy", line 231, in script
    $ inventory.add(box)
  File "game/script.rpy", line 231, in <module>
    $ inventory.add(box)
NameError: name 'box' is not defined
Update: NM- got it! ^^;

biggbuttboi
Newbie
Posts: 2
Joined: Tue Dec 06, 2016 6:41 am
Contact:

Re: Inventory Screen

#69 Post by biggbuttboi »

Hi, thank you for this wonderful inventory screen!
However, I get stuck in how to replace the text button "Show inventory" and "Close Inventory" to an image button.

Please, if someone how to do this, teach me how to do it.
Thank you!

User avatar
derkonstantin
Newbie
Posts: 10
Joined: Wed Jan 25, 2017 9:30 am
Contact:

Re: Inventory Screen

#70 Post by derkonstantin »

Hi. I am use this code in my game and have some trouble with translation for tooltip

Code: Select all

    image tooltip_inventory_dark_side_letter = LiveComposite((700, 73), (3,0), ImageReference("information"), 
                    (3,30), Text(__("Это первое, что я нашел у себя в карманах. Вы не поверите, но это - письмо!"), style="tips_bottom"))
and I have translation file

Code: Select all

    # items.rpy:58
    old "Это первое, что я нашел у себя в карманах. Вы не поверите, но это - письмо!"
    new "This was the first thing I found in my pockets. You could not believe but it's a latter!
But as I found - images in renpy create in init stage - so I see tooltip as image with untranslated text.
can I somehow fix it?
Or I need redone tooltip mech without any image?

User avatar
Lezalith
Regular
Posts: 82
Joined: Mon Dec 21, 2015 6:45 pm
Contact:

Re: Inventory Screen

#71 Post by Lezalith »

Downloaded 1500 times?
Welp, sorry to ruin the beautiful number :)

User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Re: Inventory Screen

#72 Post by GeeSeki »

I'm having a bit of trouble. Assume I bought an item and it's now in my inventory. When I refresh the game for bug testing purposes, the item disappears and I get my money back, though when I try to buy the item again, it says I already have the item (assuming I have code that allows for 1 of each item). Help? Also for some reason, the items also carry onto other save files?

Here's the code in the scrip.rpy:

Code: Select all

init python:

    class Item(store.object):
        def __init__(self, name, image="", cost=0):
            self.name = name
            self.image=image # image file to use for this item
            self.cost=cost # how much does it cost in shops?
    
    class Inventory(store.object):
        def __init__(self, money=50):
            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 sell(self, item):
            self.money += item.cost
            self.items.remove(item) 
            
        def buy(self, item):
            if self.money >= item.cost:
                self.items.append(item)
                self.money -= item
                return True
            else:
                return False
                #message = "Item added to inventory"
                #renpy.show_screen("purchase_done", message=message)
            #else:
                #message = "You don't have enough money to buy this item"
                #renpy.show_screen("inventory_popup", message=message)
                
        def earn(self, amount):
            self.money += amount
            
        def has_item(self, item):
                if item in self.items:
                    return True
                else:
                    return False
                    
###############

## Items
    fbpwmag1 = Item("Magazine", image="images/inv_fbpwmag1.png")

    chocolate = Item("Chocolate", image="images/inv_chocolate.png")
    banana = Item("Banana", image="images/inv_banana.png")    
    gun = Item("Gun", image="images/inv_gun.png", cost=60)
    laser = Item("Laser Gun", image="images/inv_laser.png")
    dirt = Item("Dirt", image="images/inv_dirt.png")
    inventory = Inventory()
And here's the code in my gamegui.rpy (not the gui.rpy)

Code: Select all

init -1 python:

    import renpy.store as store
    import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
    from operator import attrgetter # we need this for sorting items

    inv_page = 0 # initial page of the inventory screen
    item = None
    
    #def item_use():
    #    item.use()

    #Tooltips:
    style.tips_top = Style(style.default)
    style.tips_top.size=30
    style.tips_top.color="fff"
    style.tips_top.outlines=[(1, "6b7eef", 0,0)]
    style.tips_top.kerning = 5

    style.tips_bottom = Style(style.tips_top)
    style.tips_top.size=40
    style.tips_bottom.outlines=[(0, "6b7eef", 1, 1), (0, "6b7eef", 2, 2)]
    style.tips_bottom.kerning = 2
    
    style.button.background=Frame("images/inv_frame.png",25,25)
    style.button.yminimum=102
    style.button.xminimum=102
    style.button_text.color="000"
            
screen scr_gui_bag:    
    add "images/bg_bag.jpg" # the background
    tag menu
## Money Value
    hbox align (0.53,0.12) spacing 20:
        text "$"+str(inventory.money) size 60
        
## Exit
    imagebutton auto "bg_bag_exit_%s.png" xpos 0 ypos 0 focus_mask True action Return("scr_gui_bag")
    
## Inventory Slots
    $ x = 350 # coordinates of the top left item position
    $ y = 150
    $ i = 0
    $ sorted_items = sorted(inventory.items, 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)/12):
        $ next_inv_page = 0
    for item in sorted_items:
        if i+1 <= (inv_page+1)*12 and i+1>inv_page*12:
            $ x += 245
            if i%6==0:
                $ y += 240
                $ x = 350
            $ pic = item.image
            $ my_tooltip = "tooltip_inventory_" + pic.replace("images/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"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
            imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), Hide("inventory_screen")] hovered [Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
        $ i += 1
        if len(inventory.items)>12:
            textbutton _("Next Page") action [SetVariable('inv_page', next_inv_page), Show("scr_gui_bag")] xpos 0.455 ypos 0.68

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:", size=40)#, style="tips_top")
    #Tooltips-inventory:
    image tooltip_inventory_fbpwmag1=LiveComposite((1300, 80), (225,110), ImageReference("information"), (250,175), Text("{i}Magazine, Issue no. 147.{/i}.", size=40))
    #image tooltip_inventory_chocolate=LiveComposite((1300, 80), (225,110), ImageReference("information"), (250,175), Text("Generic chocolate to heal 40 points of health.", size=40))
    #image tooltip_inventory_banana=LiveComposite((1300, 80), (225,110), ImageReference("information"), (250,175), Text("A healthy banana full of potassium! Ironically, hard to use as a dildo!", size=40))
    #image tooltip_inventory_gun=LiveComposite((1300, 80), (225,110), ImageReference("information"), (250,175), Text("An gun that looks like something a cop would carry around. Most effective on humans.", size=40))
    #image tooltip_inventory_laser=LiveComposite((1300, 80), (225,110), ImageReference("information"), (250,175), Text("An energy gun that shoots photon beams.\nMost effective on aliens.", size=40))

renpyhelp
Regular
Posts: 71
Joined: Tue Feb 27, 2018 2:01 am
Contact:

Re: Inventory Screen

#73 Post by renpyhelp »

Clicking activates "selected", how can I deselect it by clicking again?
Can I limit the number of items selected to a single one?

Also, how can I make an event happen when I have a specific item selected?

ourdecemberdreams
Regular
Posts: 58
Joined: Sat Apr 15, 2017 3:26 pm
Projects: The Last December
Tumblr: ourdecemberdreams
Deviantart: ourdecemberdreams
itch: ourdecemberdreams
Contact:

Re: Inventory Screen

#74 Post by ourdecemberdreams »

leon wrote: Sat Jul 12, 2014 12:31 pm You probably forgot to create the inventory object:

Code: Select all

inventory = Inventory()
You need to create an inventory object after "label start:" and before using it. Check out the code in script.rpy just after label start.
Hey first of all, thanks for providing the inventory code! I've tried using your code for my own inventory system, but I've ran into a few problems that I can't seem to solve. Here's my code:

Code: Select all

init -1 python:
    import renpy.store as store
    import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
    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("default", 100, 50)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0):
            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.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_screen:
    tag menu

    imagemap:
        ground "gui/inventory_background.png"
        hover "gui/inventory_background.png"
        selected_idle "gui/inventory_background.png"
        selected_hover "gui/inventory_background.png"
        alpha False
        
        hotspot (1170, 0, 110, 140) action [Return(), Hide("itemmenu")]
        
    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))
    
    $ 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

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_gemblue=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A blue gem.", style="tips_bottom"))
    image tooltip_inventory_gemred=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A red gem.", style="tips_bottom"))
    image tooltip_inventory_gemgreen=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A green gem.", style="tips_bottom"))
    image tooltip_inventory_book1=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A pretty looking book.", style="tips_bottom"))
    image tooltip_inventory_book2=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A pretty looking book.", style="tips_bottom"))


# The script of the game goes in this file.

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define e = Character("Eileen")


# The game starts here.

label start:
    
    python:
        player = Player("default", 100, 50)
        player.hp = 50
        player.mp = 10
        
        gemblue = Item("Blue Gem", hp=40, image="images/inventory/gem_blue.png")
        gemgreen = Item("Green Gem", mp=20, image="images/inventory/gem_green.png")    
        gemred = Item("Red Gem", element="bullets", image="images/inventory/gem_red.png", cost=7)
        book1 = Item("Book 1", element="laser", image="images/inventory/book1.png")
        book2 = Item("Book 2", element="laser", image="images/inventory/book2.png")
        
        inventory = Inventory()
        #add items to the initial inventory:
        inventory.add(gemblue)
        inventory.add(gemgreen)
        inventory.add(gemred)

    # Show a background. This uses a placeholder by default, but you can
    # add a file (named either "bg room.png" or "bg room.jpg") to the
    # images directory to show it.

    scene bg room

    # This shows a character sprite. A placeholder is used, but you can
    # replace it by adding a file named "eileen happy.png" to the images
    # directory.

    show eileen happy

    # These display lines of dialogue.

    "Hello, world."

    e "You've created a new Ren'Py game."

    e "Once you add a story, pictures, and music, you can release it to the world!"
    
    menu:
        "Add book1":
            $inventory.add(book1)
            e "Add a book!"
            jump label1
        
        "Add book2":
            $ inventory.append(["images/inventory/book2.png", "images/inventory/book2.png", "images/inventory/book2_selected.png", "Book 2", "A book 2"])
            e "Add a book!"
            jump label1

label label1:
    e "Added a book!"

    # This ends the game.

    return
And here's the error I've got. I'm pretty sure I defined "inventory" after the "Start" label...

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 90, in execute
    screen inventory_screen:
  File "game/script.rpy", line 90, in execute
    screen inventory_screen:
  File "game/script.rpy", line 109, in execute
    $ 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
  File "game/script.rpy", line 109, in <module>
    $ 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
NameError: name 'inventory' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 30, in <module>
    ui.interact()
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ui.py", line 285, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 2538, in interact
    scene_lists.replace_transient()
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 822, in replace_transient
    self.remove(layer, tag)
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 1107, in remove
    self.hide_or_replace(layer, remove_index, "hide")
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 1031, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 443, in _hide
    self.update()
  File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 578, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 90, in execute
    screen inventory_screen:
  File "game/script.rpy", line 90, in execute
    screen inventory_screen:
  File "game/script.rpy", line 109, in execute
    $ 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
  File "game/script.rpy", line 109, in <module>
    $ 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
NameError: name 'inventory' is not defined

Darwin-17.4.0-x86_64-i386-64bit
Ren'Py 6.99.12.4.2187
Please help me out! Thanks!

M-77
Regular
Posts: 56
Joined: Tue Sep 04, 2018 7:58 am
Contact:

Re: Inventory Screen

#75 Post by M-77 »

Hello, I need some help,
I made it to show up in my game.
And I made it to to show/hide with a imagebutton.
I scaled the background image to fit from 1366x768 to my 1920x1080 resolution.
But now the items and descriptions for them are out of place of course.
I try to change the x+y coordinates. This worked for the first item. But the following ones apear still out of place.
Did I also need to scale the item images from 300x300 to ???x???. Seems not to work.
Or what size coordinates (where are they?) I need to alter in the code for the items to show correct inside the inventory boxes?
Here is my code for the imagebutton that i put in "screens.rpy" to show/open the inventory:

Code: Select all

#Inventory Icon screen display a backpack icon on mid right screen, linked to an working inventory code
screen inv_box1():
    imagebutton:
        idle "HUDINV_idle001.png"
        hover "HUDINV_hover001.png"
        xpos 0.933 ypos 0.417
        focus_mask True
        action [Hide("inventory_screen"), Show("inventory_screen")]
And here little changed code for the imagebutton function to hide/close the inventory, in "script.rpy":

Code: Select all

#+++++++++++++++++++++++++++INVENTORY pop up screen is here: 
init -1 python:
    import renpy.store as store
    import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
    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("Derp", 100, 50)
    
    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0):
            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.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/frameInv.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")]
#Imagebutton for hide inventory:
    imagebutton idle "HUDINV_idle001.png" hover "HUDINV_hover001.png" xpos 0.933 ypos 0.417 action [Hide("inventory_screen")]
    $ 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 += 209
                $ x = 607
            $ 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_screen"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "sound/klick002.ogg"), 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

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_chocolate=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("Generic chocolate to heal\n40 points of health.", style="tips_bottom"))
    image tooltip_inventory_banana=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("A healthy banana full of potassium! You can also use it as ammo for your guns! O.O Recharges 20 bullets.", style="tips_bottom"))
    image tooltip_inventory_gun=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("An gun that looks like something a cop would\ncarry around. Most effective on humans.", style="tips_bottom"))
    image tooltip_inventory_laser=LiveComposite((665, 73), (3,0), ImageReference("information"), (3,30), Text("An energy gun that shoots photon beams.\nMost effective on aliens.", style="tips_bottom"))
Nothing changed after the "label start:" line. I am just getting used to inventory function now. ":

Code: Select all

label start:
init -1 python:
    player = Player("Derp", 100, 50)
    player.hp = 50
    player.mp = 10
    chocolate = Item("Chocolate", hp=40, image="gui/inv_chocolate.png")
    banana = Item("Banana", mp=20, image="gui/inv_banana.png")    
    gun = Item("Gun", element="bullets", image="gui/inv_gun.png", cost=7)
    laser = Item("Laser Gun", element="laser", image="gui/inv_laser.png")
    inventory = Inventory()
    #add items to the initial inventory:
    inventory.add(chocolate)
    inventory.add(chocolate)
    inventory.add(banana)
Last edited by M-77 on Sun Jun 02, 2019 4:45 am, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users