Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

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
MidnightCafe
Newbie
Posts: 3
Joined: Fri Jun 09, 2017 4:20 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED

#46 Post by MidnightCafe » Fri Jun 09, 2017 4:52 pm

There's probably an easy solution to this, but I'm having trouble getting the inventory screen over the dialogue box.

And while I'm at it, is it at all possible to have the dialogue box close/hide whenever the inventory screen is opened?
Attachments
979798.PNG

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

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED

#47 Post by noeinan » Sun Jun 11, 2017 4:00 pm

MidnightCafe wrote:There's probably an easy solution to this, but I'm having trouble getting the inventory screen over the dialogue box.

And while I'm at it, is it at all possible to have the dialogue box close/hide whenever the inventory screen is opened?
I don't have the code pulled up right now, but I believe you assign menu priority with "zorder" and you can make certain screens disappear when another screen opens by giving them both the same menu tag. (Ex. menu, menu1, menu2.) If you search the forums for those tags you should be able to get some more information on them.
Image

Image
Image

User avatar
MidnightCafe
Newbie
Posts: 3
Joined: Fri Jun 09, 2017 4:20 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED

#48 Post by MidnightCafe » Tue Jun 20, 2017 2:10 pm

daikiraikimi wrote: I don't have the code pulled up right now, but I believe you assign menu priority with "zorder" and you can make certain screens disappear when another screen opens by giving them both the same menu tag. (Ex. menu, menu1, menu2.) If you search the forums for those tags you should be able to get some more information on them.
Both of these worked, thank you!

I don't think the tutorial covered it, but is it possible to keep someone from trading an item unless you have a specific item? (Maria has a stopwatch, but won't trade unless you have milk, for example)

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

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED

#49 Post by noeinan » Tue Jun 20, 2017 7:11 pm

MidnightCafe wrote:
Both of these worked, thank you!

I don't think the tutorial covered it, but is it possible to keep someone from trading an item unless you have a specific item? (Maria has a stopwatch, but won't trade unless you have milk, for example)
Glad I could be of use! I don't think there's anything like that currently programmed in. The easiest way I can think of implementing this is to simply not add the stopwatch to the inventory unless the player has milk. (Ex. If [player has milk] then [add stopwatch to Maria's inventory].)

However, that doesn't really fix things if 1. you want the player to see the stopwatch, and then not be able to buy it, therefore they go on a search for milk, and 2. if you want the player to trade the stopwatch *for* milk, instead of the trade only being active if milk is in the inventory.

Looking at the code...

Code: Select all

    def trade(seller, buyer, item):
        seller.drop(item[0])
        buyer.take(item[0])     
The trade function doesn't even trade one item for another. It's really just taking something without paying for it, lol. If you wanted to set up something that would allow you to trade one item for another item, my guess is you would have to make a new function that would take the seller, buyer, and then seller's item and buyer's item. Something like this:

Code: Select all

    def real_trade(seller, buyer, Sitem, Bitem):
        seller.drop(Sitem[0])
        buyer.take(Sitem[0]) 
        buyer.drop(Bitem[0])
        seller.take(Bitem[0])    
And then further you need to determine what item can be exchanged for what other items. So you would need to add if statements in there. Maybe something like...

Code: Select all

    def watch_trade(seller, buyer, Sitem, Bitem):
        if Sitem = "watch" and Bitem = "milk":
                seller.drop(Sitem[0])
                buyer.take(Sitem[0]) 
                buyer.drop(Bitem[0])
                seller.take(Bitem[0])    
        else:
                jump no_milk
And then no_milk would be a label where the shopkeeper explains they will only trade the watch for milk.

The syntax on that is, I'm pretty sure, not correct since all the functions are written inside a python block, but it seems like that's the basic structure you would need. (Just translate into python proper, if you post on the forums someone might be able to help more with that.) The problem with this is that you need to make a new function for every single item-item trade. Not a problem if you only have a few plot-pertinent trades, but it's not going to work if you want to be able to trade any two items of equal value, for example.

There is also "trade mode" in various places throughout the code, and you would probably need to make a new "trade mode" that has actual trading instead of moving things around. Maybe change the old "trade mode" into "move mode" or "storage mode" and then make a new "trade mode" that allows for trading of items. (Or, instead, you could trigger the trade through dialogue instead of using the shop screen, which honestly would make things easier.)

OH. That made me think of another much easier solution. Don't put the watch in the inventory at all, or put it in and make it an unreasonably high price. Then use dialogue with the shopkeeper entirely-- if the player has milk, the shopkeeper will ask the player to trade milk for the watch. Then just add the items to their appropriate inventories based on dialogue choices, skipping all the more complicated code all together. Ex:

Code: Select all

shopkeeper "Oh, if only I had some milk."

if [player has milk in their inventory]:
     player "I have milk!"
     shopkeeper "Wow! Will you trade for this stopwatch?"
     menu:
          Yes
               [remove milk from inventory]
               [add stopwatch to inventory]
               shopkeeper "Thank you so much!
          No
               shopkeeper "Oh, that's too bad..."
else: 
     shopkeeper "If someone had milk, I would trade them my very expensive stopwatch... But I guess not."
(This syntax also probably not accurate, it's been a while, but hope it gets the general idea across.)
Image

Image
Image

User avatar
Luxliev
Veteran
Posts: 242
Joined: Sat Feb 07, 2015 11:01 am
Soundcloud: Luxliev
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#50 Post by Luxliev » Fri Jul 28, 2017 7:42 am

I really like it. Don't know if it's expected behaviour but you can sell stuff for 0 g (Coin).
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc

Forum with my music: http://luxliev.proboards.com/

User avatar
Modzso
Newbie
Posts: 24
Joined: Fri Jun 24, 2016 5:38 am
Projects: Ghosts of Fablees - Chapter 1.
Tumblr: captainmodzso
Deviantart: nephle
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#51 Post by Modzso » Fri Aug 11, 2017 7:30 am

Someone has solved the usuable items already? :)
An item in the inventory when I click on it, it's gonna give you certain things / benefits? Like an apple, clicked on it and it gives a few hp? :)

Any solution for that? :)

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

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#52 Post by noeinan » Sun Aug 13, 2017 4:52 am

Making an item that changes a variable when clicked is easy enough! You just need to add SetVariable as one of the actions.

Code: Select all

    $ apple = Item("Apple", "A juicy fruit which restores 5 health.", "inv/apple.png", 100, act=[Show("inventory_popup", message="+5 Health"), SetVariable('health',health+1)])
However, after clicking the apple it will remain in your inventory. Every time you click the apple it will give you another 5 health. If you want to consume the apple after use, you will need to code an action that removes an apple from the inventory. I'm not 100% on how to do that myself, though. My best guess would be something like this...

Code: Select all

    class UseItem(Action):

        def __init__(self, item):
            self.item = item

        def __call__(self):
            pc_inv.drop(item[0])


And then changing the item definition to add the new action:

Code: Select all

    $ apple = Item("Apple", "A juicy fruit which restores 5 health.", "inv/apple.png", 100, act=[UseItem(apple), Show("inventory_popup", message="+5 Health"), SetVariable('health',health+1)])
But there are probably some errors in there regarding how it "talks" to other areas of the code. Maybe someone with more coding practice would be able to narrow it down from there?
Image

Image
Image

User avatar
Yadi
Newbie
Posts: 4
Joined: Sat Jan 14, 2017 10:16 am
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED

#53 Post by Yadi » Thu Sep 07, 2017 7:49 am

daikiraikimi wrote:
Mon Jan 30, 2017 6:27 pm
Yadi wrote: iam tried to make a cafe gameplay example
so, iam change the items acts to jump to label test if we clicked the icon and then iam put this code in label test

Code: Select all

label test:
  if item[0].dishOrg > 50: 
     $costumerhappy = + 6
      call Satisfied_costumer from          Satisfied_costumer
but i got an error, said: name 'item' isn't defined, then what the right code of it ?
I am not an expert by any means, but here is my best guess:

Everywhere else in the code that uses item directly is a function, inside a python block. Variables inside of functions aren't defined outside of that function. It seems to me that you will need to make a function that takes in information about the item and then calls "Satisfied_customer" if the conditions are met.

iam barely saw this, because i am not getting any notifications if my question has been answered, so i thought iam just beings ignored, but thanks for replied even i don't need this anymore, and you know, your inventory-system is interesting so that's why i was trying to learn coding from it...

thanks once again

User avatar
niannn
Regular
Posts: 56
Joined: Tue Jun 27, 2017 1:04 am
Completed: Keynote, Die.Alone?, The Villaintine
Projects: The Villaintine: Sepia
Tumblr: niaaannn
itch: niannn
Location: Philippines
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#54 Post by niannn » Sat Jan 06, 2018 11:07 am

just wondering if there's a way to solve this one?

Image

As you can see from the image, the description of an item upon hovering doesn't show up where it's supposed to be. I don't have any idea how to fix this and I would really appreciate help. Also, thank you in advance!

sidenote: I am not so well-versed with python and modified the code only a little based on the basic guidelines on how to use it (I did try to fix this with my basic understanding but I think all my attempts are not getting me anywhere and I need help). So, I'm still a rookie. I might ask again if I don't understand the answer so I hope you'll be patient with me. Once again, thank you very much in advance.

TheChatotMaestro
Regular
Posts: 85
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#55 Post by TheChatotMaestro » Sat Feb 10, 2018 7:39 pm

Hi! I couldn't figure something out and I wanted to know if it was possible or not.
Is there a way to have a chest react to something you put inside, if that makes sense? I'm trying to use this with a dating sim, and I want to be able to use this to give a gift to a character, but only one at a time, and have it jump to a reaction right away. Is there a way to do this?

Edit: I'm working on a way to do this but it's kinda confusing.

Code: Select all

label start:  
    
    $ jane_inv = Inventory("Items")
    $ sword = Item("Not A Sword", "It looks like a sword, but it isn't.", "images/sword.png", 500, call ReactSword)
    $ interaction = None
    $ characterabond = 0
    $ characterbbond = 0
    jump beginning
    
label beginning:
    menu:
        "Character A":
            jump CharacterA
        "Character B":
            jump CharacterB
        "Check Bond":
            jump bondcheck
    
label CharacterA:
    "Hey!" 
    menu:
        "Give Gift":
            $ interaction = A
            show screen inventory_screen(jane_inv)
    menu:
        "Back":
            jump beginning
        
    
    
label CharacterB:
    "Hi." 
    menu:
        "Give Gift":
            $ interaction = B
            show screen inventory_screen(jane_inv)
    menu:
        "Back":
            jump beginning
    
    
    
    
label ReactSword:
    if interaction == none:
        Show("inventory_popup", message="You can't use this here.")
        
        
    else:
        if interaction == A: 
            "Really? It's not a sword?"
            $ characterabond += 1
            $ interaction = none
            hide screen inventory_screen
            jump beginning
        else:
            if interaction == B:
                "I thought it was a sword..."
                $ characterbbond += 1
                $ interaction = none
                hide screen inventory_screen
                jump beginning
    
label bondcheck:
    "A's bond is [characterabond] and B's bond is [characterbbond]!"
    jump beginning

There's my code, it's just something I made really quick to try and test it. When I try and play the game...

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 50: expected statement.
    Show("inventory_popup", message="You can't use this here.")
                                                               ^

Ren'Py Version: Ren'Py 6.99.12.4.2187
Can you even make an item jump to a label when you use it, or can it only make text pop up on the screen?

TheChatotMaestro
Regular
Posts: 85
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#56 Post by TheChatotMaestro » Fri Apr 13, 2018 3:53 pm

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/definitions.rpy", line 126, in script
    $ osanoitem = Item("Osano Najimi", "")
  File "game/definitions.rpy", line 126, in <module>
    $ osanoitem = Item("Osano Najimi", "")
NameError: name 'Item' is not defined

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

Full traceback:
  File "C:\Users\SerebiiGamer\Desktop\renpy-6.99.12.4-sdk\renpy\bootstrap.py", line 295, in bootstrap
    renpy.main.main()
  File "C:\Users\SerebiiGamer\Desktop\renpy-6.99.12.4-sdk\renpy\main.py", line 419, in main
    game.context().run(node)
  File "game/definitions.rpy", line 126, in script
    $ osanoitem = Item("Osano Najimi", "")
  File "C:\Users\SerebiiGamer\Desktop\renpy-6.99.12.4-sdk\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\SerebiiGamer\Desktop\renpy-6.99.12.4-sdk\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/definitions.rpy", line 126, in <module>
    $ osanoitem = Item("Osano Najimi", "")
NameError: name 'Item' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
This just showed up out of nowhere. Didn't edit the file, the way the item was defined, or anything relevant except a separate item defined after the one in question. Any clue how to fix?

TheChatotMaestro
Regular
Posts: 85
Joined: Mon Jul 31, 2017 8:33 am
Deviantart: LedianWithACamera
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#57 Post by TheChatotMaestro » Sun Apr 29, 2018 1:29 pm

Does anyone have any clue on how to fix the item not defined issue? Really sorry to double post, it's just my project literally will not launch without it, the error message shows up in an editra window instead of the normal error window, I'm super desperate for help right now.

EroLifeDev
Newbie
Posts: 2
Joined: Thu Oct 12, 2017 4:21 am
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#58 Post by EroLifeDev » Mon Jul 02, 2018 8:38 pm

This script is really great!

But, am I the only one with the issue that after saving and reloading a game, the inventory reverts back to default? Current items are not saved.

I've tried initializing the inventory before the begin label, as well as after it. I can't figure it out.

Has anyone fixed this issue?

xplosion
Newbie
Posts: 10
Joined: Sat Jul 21, 2018 3:49 pm
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#59 Post by xplosion » Sat Jul 28, 2018 7:58 am

same problem, things are not saved in storage when you load a save.

any fix? or updated version?

User avatar
niannn
Regular
Posts: 56
Joined: Tue Jun 27, 2017 1:04 am
Completed: Keynote, Die.Alone?, The Villaintine
Projects: The Villaintine: Sepia
Tumblr: niaaannn
itch: niannn
Location: Philippines
Contact:

Re: Infinite, Stackable Inventory/Crafting/Vendor - UPDATED v1.5

#60 Post by niannn » Sat Jul 28, 2018 8:52 am

Hello, I encountered this problem before and the solution I found so far is that you need to declare your cookbook and your inventories as default.

Here's a code snippet from my second game showing how I declared just that place this code just above 'label start'. I hope that helps :)

Code: Select all

init:
    default cookbook = list()
    default inv = Inventory("Inventory")
    
    ## Inventory Items
    $ medicine = Item("Item", "some item")
Image Image ImageImage

Post Reply

Who is online

Users browsing this forum: Google [Bot]