Explain to me like I'm 5: Inventory System

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
User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Explain to me like I'm 5: Inventory System

#16 Post by trooper6 »

If you are getting the exact same error as before, then your error may not be with that chunk of code but some other part of your code...especially considering the error report you posted lists errors popping up in all sorts of files not just your script file.

Why don't you zip your entire project and attach it here so that we can take a look at it to see what might be going wrong?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Explain to me like I'm 5: Inventory System

#17 Post by JaxxyLupei »

Here you go: https://www.mediafire.com/?oncfdqc377ca2i2 the file itself is large so I apologize in advance :? I'm hoping the solution is simple though.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Explain to me like I'm 5: Inventory System

#18 Post by trooper6 »

Thanks for linking it....but before I go into these files...the first thing I did was use the "Check Script (Lint)" command from Renpy on your project. It came up with a number of errors.
game/Carrie.rpy:1446 The image named 'carrie f 9 8' was not declared.

game/Carrie.rpy:1598 The image named 'carrie f confsed 7' was not declared.

game/Misty.rpy:1089 The image tag 'nidnight' is not the prefix of a declared image, nor was it used in a show statement before this hide statement.

game/definitions.rpy:365 Image hannah happy 7 uses file 'img/bachlorettes/Hannah Happy 7.png', which is not loadable.

game/definitions.rpy:487 Image michelle blush 1 uses file 'img/bachlorettes/Michelle Blush 1.png', which is not loadable.

game/doubleScenes.rpy:1616 The image tag 'mischelle' is not the prefix of a declared image, nor was it used in a show statement before this hide statement.

game/doubleScenes.rpy:1846 The image named 'bg school hall 1' was not declared.

game/doubleScenes.rpy:1975 'carrie_love is >= 5' could not be compiled as a python expression, in a condition of the if statement.

game/doubleScenes.rpy:2176 The image named 'carrie f angry 7' was not declared.

Style style.say_label uses file 'inkpen2-script.ttf', which is not loadable.
#1, #2, #3, #6 seem to be typos.
#4, #9, #10 are a missing files (for example, there is no Hannah Happy 4.png in your img/bachlorettes folder)
#5 is a typo in the file name
#7 you never declared an image as bg school hall 1, you have a bunch of bg school hallway images...this should be fixed.
#8 you typed: "if carrie_love is >= 5", that should be "if carrie_love >= 5"

You should fix those problems first off.

As for your store problem I noticed two things:
1) In your shops file, all your items are placed before the label giftShop...so I don't think the program ever gets around to creating them...it might, but it seems not. You might want to try placing those items inside your giftShop label, right before the "What do you want to buy?" line, of place them right after your start label where you have all of your other variables.

You have a lot of variables. I was just reading about something that someone did that seemed like it would be pretty useful. That person created a renpy file called variables.rpy. In that file they had a "variable" label where they placed *all* of their variables for the game. Then right after the start label, they called that variable label. This way everything gets initialized right in the beginning, but you don't have a massive amount of variables taking up a huge chunk of space right after the start label. Anyway, something to think about.

2)So I placed the variables inside the giftShop label and started playing through.
I got an error when I went to buy a lollipop...but not the one you had originally (it seemed moving the variables fixed that.)
What was the error?
While running game code:
File "game/script.rpy", line 228, in script call
call daySix_General
File "game/commonScenes.rpy", line 927, in script call
call town
File "game/WeekendGeneralScenes.rpy", line 8, in script call
call mall
File "game/WeekendGeneralScenes.rpy", line 52, in script call
call shopkeeperintro
File "game/shopkeeper.rpy", line 37, in script call
call giftShop
File "game/shops.rpy", line 58, in script
$ result = myBackpack.add_Item(cherrylolli)
File "game/shops.rpy", line 58, in <module>
$ result = myBackpack.add_Item(cherrylolli)
File "game/Inventory.rpy", line 35, in add_Item
item.amount += 1
AttributeError: Item instance has no attribute 'amount'
So I checked out the inventory file...and there was the discrepancy. The Backpack class you created assumes an Item that has an amount attribute, which it adds to. But the Item class you created has no amount variable.

Your item class should look like this:

Code: Select all

    class Item():
        def __init__(self, name, cost, wt, hp=0, amount=0, **kwargs):
            self.name = name
            self.cost = cost
            self.wt = wt
            self.hp = hp
            self.amount = amount
Changing the Item class to this fixes your problem.

Now in the process of checking this out, I noticed a few red flags.
Your item class also contains a use method:

Code: Select all

        def use(self):
            if self.hp>0:
                player.hp = player.hp+self.hp
                if player.hp > player.max_hp:
                    player.hp = player.max_hp
                inventory.drop(self)
And um...I don't see how this method is going to work. Nowhere in your files that I can see have you defined anything called "player" with hp and max_hp attributes--so this use method has nothing to work on. Additionally you have nothing defined as "inventory"--so that part isn't going to work either. The only place I see a reference to "inventory" is in your giftstore.rpy file and that file a) seems to be a bit of a mess in terms of indentation and b) also seems to be a file you never use. If you aren't using it, you might as well just delete it. Also...there seems to be no time where they player is given the option of using their items...so...it seems like this method is never going to be used.

Last quick thing, in your script file you have:

Code: Select all

    $ backpack = set()
You never use this, so you might as well delete it.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

JaxxyLupei
Regular
Posts: 30
Joined: Tue Apr 08, 2014 10:34 pm
Projects: Dance With Me? (A date sim)
Location: NY

Re: Explain to me like I'm 5: Inventory System

#19 Post by JaxxyLupei »

Yikes...seems there was a lot more underlying problems than I realized.

My friend and I aren't anywhere near experts at coding; most of the stuff we have on here are through trial and error/copying and pasting and worst case scenario we have someone look at our codes if we're stuck. I suppose we should have paid more attention to tutorials lol.

I moved the items, added the amount thing, and holy crap it worked! Thank you very much for taking the time to look through the files, I feel a little dumb now but I'm glad it was a simple fix, or else I would have torn my hair out! Now that that's out of way, I can work on the other issues.

Thanks again!

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Explain to me like I'm 5: Inventory System

#20 Post by trooper6 »

No problem!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Sleepy
Regular
Posts: 136
Joined: Wed Nov 27, 2013 6:12 pm
Projects: Camera Anima
Organization: EXP-resso Mutt
Tumblr: sleepy-does-games.tumblr.com
itch: https://expressomutt
Contact:

Re: Explain to me like I'm 5: Inventory System

#21 Post by Sleepy »

Bookmarking this thread. The inventory here is different from how I'm doing mine but this has been so, so useful for someone who doesn't know much about programming and even helped me figure out how to do a stripped down but workable version of the item description feature I'd seen in other inventory codes. Thanks ^^.~
W.I.P.

Image

Complete

Image Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Explain to me like I'm 5: Inventory System

#22 Post by trooper6 »

As soon as I get some extra free time, I'll clean it up, expand it a bit and put it in the cookbook.

So I'm glad it was useful!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users