Inventory Help

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.
Message
Author
CharacterGreen
Newbie
Posts: 14
Joined: Mon Jun 18, 2018 9:15 pm
Contact:

Re: Inventory Help

#16 Post by CharacterGreen »

@trooper6 The folder structure goes from game to images to items to my image (candybar.png)

@Alex, I tried stretching the background and all it did was make my image look distorted and larger (and the items didn't show up either)

I also changed my names so that there would be no overlapping names and that still hasn't worked

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Inventory Help

#17 Post by Alex »

Hm, could you make a sample project with all images and inventory code and share it to let people try to find solution?

CharacterGreen
Newbie
Posts: 14
Joined: Mon Jun 18, 2018 9:15 pm
Contact:

Re: Inventory Help

#18 Post by CharacterGreen »

Here's the sample file, hopefully you'd be able to fix it!
Attachments
Inventory_Help.rar
(1.55 MiB) Downloaded 21 times

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Inventory Help

#19 Post by Alex »

Well, you've deleted the "side "c r":" line...
It must be

Code: Select all

    vbox:
        pos (363, 0.05) anchor (0.0, 0.0)
        
        #### inventory slots
        frame:
            background Frame("images/inventory_screen.png", 1, 1)  #file name including path from game folder (if needed)
            side "c r":
                # size of the inventory visible area
                area (0, 0, inv_item_width*inv_cols+inv_spacing*(inv_cols-1), inv_item_height*inv_rows+inv_spacing*(inv_rows-1))

                viewport id "vp":
                    draggable True
Also, try to change your "inventory_screen.png" to have just a frame (without slots). Then make a separate slot background image and use it like

Code: Select all

                        for item in inventory:
                            button:
                                background Frame("images/inventory_slot.png", 1, 1)
                                xysize(inv_item_width, inv_item_height)
                                
                                #### Choose one option and delete the other:
                                
                                
                                # 2) show an image
                                add item["img"] align (0.5, 0.5)

CharacterGreen
Newbie
Posts: 14
Joined: Mon Jun 18, 2018 9:15 pm
Contact:

Re: Inventory Help

#20 Post by CharacterGreen »

Thank you so much for your help! It works perfectly as I would want it to be! Do you think you could tell me if there was a way to offset the background image or the area of the grid/inventory and also how do I get rid of the slider that's in frame (This is for sure my last question)

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Inventory Help

#21 Post by Alex »

Was a bit busy - real life, you know...
Try something like

Code: Select all

screen onscreeen_button():
    imagebutton idle "inventory" hover "inventory_hovered" xpos 1080 ypos 66 action If(not renpy.get_screen("inventory_scr"), Show("inventory_scr"), Hide("inventory_scr"))
    
screen inventory_scr():
    modal True
    imagebutton idle "inventory" hover "inventory_hovered" xpos 1080 ypos 66 action If(not renpy.get_screen("inventory_scr"), Show("inventory_scr"), Hide("inventory_scr"))
    default description = None
    
    vbox:
        pos (363, 0.05) anchor (0.0, 0.0)
        
        #### inventory slots
        frame:
            background Frame("images/inventory_screen.png", 1, 1)  #file name including path from game folder (if needed)
            side "tl c":
                # size of the inventory visible area
                area (0, 0, inv_item_width*inv_cols+inv_spacing*(inv_cols-1)+inv_offset*2, inv_item_height*inv_rows+inv_spacing*(inv_rows-1)+inv_offset*2)
                
                null width inv_offset height inv_offset 

                viewport id "vp":
                    draggable True
                    mousewheel True


                    grid inv_cols max(inv_rows, len(inventory)/inv_cols+1) spacing inv_spacing:
                        for item in inventory:
                            button:
                                xysize(inv_item_width, inv_item_height)
                                background Frame(Solid("#c0c"), 1, 1) # <--- put image for the frame
                                
                                
                                # 2) show an image
                                add item["img"] align (0.5, 0.5)
                                text item["name"] align (0.5, 0.95) # if needed
                                
                                action NullAction()
                                
                                hovered SetScreenVariable("description",item["dscrptn"])
                                unhovered SetScreenVariable("description",None)
                        
                        # empty slots to fill the grid
                        if len(inventory) < inv_cols*inv_rows:
                            for i in range (inv_cols*inv_rows-len(inventory)):
                                button:
                                    xysize(inv_item_width, inv_item_height)
                                    background Frame(Solid("#c0c"), 1, 1) # <--- put image for the frame
                                    action NullAction()
                        else:
                            for i in range ((len(inventory)/inv_cols+1)*inv_cols-len(inventory)):
                                button:
                                    xysize(inv_item_width, inv_item_height)
                                    background Frame(Solid("#c0c"), 1, 1) # <--- put image for the frame
                                    action NullAction()
                            
                #vbar value YScrollValue("vp") # comment or delete this line if not need the scrollbar
                
        #### description
        if description:
            text "{i}[description]{/i}" size 25 xalign 0.5
        else:
            null

# something about our inventory...
define inv_cols = 3
define inv_rows = 3
define inv_item_width = 143
define inv_item_height = 143
define inv_spacing = 36
define inv_offset = 72

Post Reply

Who is online

Users browsing this forum: Andredron