Inventory Menu/Price Code

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
User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Inventory Menu/Price Code

#1 Post by Starlightkitty7 » Thu Jun 19, 2008 8:29 pm

Hey everyone! I'm really making this game more and more complicated. ^_^' It's fun anyways but once again I'm stuck.

I've already created menu's where you can choose items and such. But how would I create a "Shop menu?" I made it and I added items and dialog. But how would I assign prices to them? Add a price system in the game?
Also, going along with that I should add I don't have a inventory menu yet. But I want that once you buy an item the user can select it in their inventory and a pic or the costume or item is displayed (but that would be a drawn image file.)

Well here is my menu (very simplified)for example that works great so far:

Code: Select all

label store_menu:
   "Mage Gown": 
         s "I love this outfit"
         jump con_2
   "Warrior Suit":
         s "This is more of my style!" 
         jump con_1
label con_1:
      c "Do you like it?"
      s "Yeah I think I may get it!" 
Help please?

Also! I want to say thank you to those who helped me out in my previous topics. The coding are working wonderful and I appreciate all the help greatly!

User avatar
BellosTheMighty
Regular
Posts: 63
Joined: Wed Aug 01, 2007 11:11 pm
Contact:

Re: Inventory Menu/Price Code

#2 Post by BellosTheMighty » Thu Jun 19, 2008 9:08 pm

It doesn't seem hard to me- create a numerical value for the amount of money your character has, insert the price of an item in it's description somewhere, and then just add and subtract as necessary. In a pinch, you don't even need to display the amount of money constantly since the user doesn't need it constantly, at most he needs to check it on walking into the shop and again before he makes the purchase. If you've ever played the old DOS game "Alien Logic", they did shops as standard conversations that went similar to this:

"I walk into the store."
"Let's see, I have 86 gold..."
"Hmm... what do they have?"
"A short sword for 23 gold..."
"A long sword for 68 gold..."
"A big, wide, hardened sword of charm maidens for 197 gold!"
"What should I get?"
*prompt user to choose purchase*
"Yeah, the long sword is probably best- Let's see, can I afford this?"
"I have 86 gold..."
*prompt user y/n*

Unless I'm mis-interpreting your question?
----
"Yes, ninety percent would never get finished, and ninety percent of the rest would suck. That's the way it always works. That's how you get stuff that kicks ass." -Andrew Plotkin

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Inventory Menu/Price Code

#3 Post by JQuartz » Fri Jun 20, 2008 1:36 am

For price listings you could write down the value beside the name of the item itself and deduct the amount of money after the player selects the choice like so:

Code: Select all

label store_menu:
    menu:
       "Mage Gown $100":
         $ money-=100 
         $ mage_gown=True
         s "I love this outfit"
         jump con_2
       "Warrior Suit $150":
         $ money-=150
         $ warrior_suit=True
         s "This is more of my style!" 
         jump con_1
For inventory you can try the following:

Code: Select all

    menu:
      'This is your inventory'
        'Warrior Suit' if warrior_suit:
            show item warriorsuit
            'Defence +20'
        'Mage Gown' if mage_gown:
            show item magegown
            "Defence +5"
    return 
These codes aren't optimal especially if you have a large inventory but they are, I believe, the simplest to learn. (The larger/more complex inventories, you'll need to learn ui and python)
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Gau_Veldt
Regular
Posts: 86
Joined: Tue Jun 10, 2008 8:22 pm
Location: Prince George, BC
Contact:

Re: Inventory Menu/Price Code

#4 Post by Gau_Veldt » Fri Jun 20, 2008 6:20 am

Starlightkitty7 wrote:Hey everyone! I'm really making this game more and more complicated. ^_^' It's fun anyways but once again I'm stuck.

I've already created menu's where you can choose items and such. But how would I create a "Shop menu?" I made it and I added items and dialog. But how would I assign prices to them? Add a price system in the game?
Also, going along with that I should add I don't have a inventory menu yet. But I want that once you buy an item the user can select it in their inventory and a pic or the costume or item is displayed (but that would be a drawn image file.)

Well here is my menu (very simplified)for example that works great so far:

Code: Select all

label store_menu:
   "Mage Gown": 
         s "I love this outfit"
         jump con_2
   "Warrior Suit":
         s "This is more of my style!" 
         jump con_1
label con_1:
      c "Do you like it?"
      s "Yeah I think I may get it!" 
Help please?

Also! I want to say thank you to those who helped me out in my previous topics. The coding are working wonderful and I appreciate all the help greatly!
Any more than a handful of items and I'd consider looking at a bit of Python to make use of lists and dictionaries to eliminate a bunch of repetitive boiler plate you are going to run into with a lot of items.

Also the menu statement doesn't cope with changing options. For that you'll want to use look up how to use the ui functions. The ui gives you more freedom too, such as letting you reuse the code so you could have more than one "shop" with different inventories.

A price system would involve a currency

Code: Select all

$ money=500
and then a shop's code testing the price of an item against the player's money to make sure he or she has enough of it using if. To avoid awkward repetitive dialog you'd be best to def a python function for handling a shop. The way I'd most likely do it is with a dictionary defined to be the "master list" which would have the names of items as keys and the prices as values

Code: Select all

init:
  items={
    "apple" : 5,
    "ring" : 150
    }
You could then use lists for the player's inventory by naming the items the player has as elements in the list. You'd also use lists like this to pass to the shop function to give it the list of items that "shop" has for sale (I'd add an optional second argument to my shop handler for a discount/gouge factor). Other thing the shop handler would need to know is the player's on hand cash and player's current inventory (if you want to prevent buying more than one of something).

Edit: I forgot to mention that your shop handler would look up items with code that looks like

Code: Select all

$ what='apple'
$ price=items[what]
e "Your %(what)s costs %(price)d quid."

User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Re: Inventory Menu/Price Code

#5 Post by Starlightkitty7 » Fri Jun 20, 2008 8:02 am

Hm..I was thinking i might have to learn ui now too. I was working on just the simplistic way of using menu and relabeling everything although it took up more room. Ui might clean it all up. ^_^

Thanks for the help everything and the examples. I'll play around and see which one is best. I needed a few examples to get an idea. Thanks!

User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Re: Inventory Menu/Price Code

#6 Post by Starlightkitty7 » Fri Jun 20, 2008 6:59 pm

I was checking out ui's on the Ren'py wiki and its a little difficult to understand. Mainly I don't know where to start to be honest or if I can use it with what I already made. Is it possible to make a complex game and just use the simplistic codes like i've been doing?

And for those who know ui. Where did you learn it from? (Sites?)

Thanks.

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Inventory Menu/Price Code

#7 Post by JQuartz » Sat Jun 21, 2008 1:24 am

Starlightkitty7 wrote:And for those who know ui. Where did you learn it from? (Sites?)
I learn it from asking around here and through trial and error. Once you get the basics of ui and python, the wiki becomes quite useful (because you'll be able to understand it by then)
if I can use it with what I already made.
I don't know what you've already made so I can't tell.
Is it possible to make a complex game and just use the simplistic codes like i've been doing?
Yes but from my experience the coding will end up complex nonetheless because there will be too much to keep track of. But then again I don't really have that much experience anyway so maybe I'm just doing it wrong.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Re: Inventory Menu/Price Code

#8 Post by Starlightkitty7 » Sat Jun 21, 2008 1:35 pm

JQuartz wrote:
Starlightkitty7 wrote:And for those who know ui. Where did you learn it from? (Sites?)
I learn it from asking around here and through trial and error. Once you get the basics of ui and python, the wiki becomes quite useful (because you'll be able to understand it by then)
if I can use it with what I already made.
I don't know what you've already made so I can't tell.
Is it possible to make a complex game and just use the simplistic codes like i've been doing?
Yes but from my experience the coding will end up complex nonetheless because there will be too much to keep track of. But then again I don't really have that much experience anyway so maybe I'm just doing it wrong.
Ah ok. Thanks for the reply. Yeah I figured the codes would get all over the place by then but I guess I'll try it.
I'm more of a visual learner so "Examples" work better for me but I have no idea where to start with ui. Is ui mixed with those simplistic codes? Or is it a whole new thing?

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Inventory Menu/Price Code

#9 Post by JQuartz » Sat Jun 21, 2008 1:55 pm

Is ui mixed with those simplistic codes? Or is it a whole new thing?
I consider ui and python to be different class of their own-which is programming. Renpy seems to be more like a script (okay now we are in this scene and we will show these two people...) so the jump from Renpy to ui and python is quite hard.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Re: Inventory Menu/Price Code

#10 Post by Starlightkitty7 » Sat Jun 21, 2008 10:15 pm

hm..oh ok. I see. ^_^
Which is why ui has its own 'interact' coding and jump as well.
Heres a quick question to clear up ui a little. ^_^

What's the diffrence between ui jump and python jump? Or ui interact and regular interact?

Code: Select all

(Regular meaning::
ex: "c" has been defined as a name and then later is used like: c "Hi there!") 

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Inventory Menu/Price Code

#11 Post by Jake » Sat Jun 21, 2008 11:07 pm

Starlightkitty7 wrote: What's the diffrence between ui jump and python jump? Or ui interact and regular interact?
I'm not sure why JQuartz is using the terms he is, but... ui is just a Python module available for use within Ren'Py scripts. There are several methods in the ui module which have to be used in a particular way to construct User Interfaces, but it's not a separate language or a separate scope or anything, it's still Python code.

The strict answers to your questions are that there isn't a Python 'jump', and there isn't a Python 'interact', so the questions can't be answered.

The difference between a Ren'Py script jump and ui.jumps is that the Ren'Py jump instantly jumps to the label given, while the ui.jumps method returns a function which jumps to the label given if it's called. Because some ui calls take a function as a parameter (for example, the 'clicked' of ui.button) it's useful to have that ui.jumps call if you want to have a button which jumps to a particular label when it's clicked.

The only interact I've ever seen in Ren'Py is the ui.interact call, so I don't think that question can be answered. Basically, it means "I'm finished describing this UI, throw it up on the screen and let the user play with it".
Server error: user 'Jake' not found

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Inventory Menu/Price Code

#12 Post by JQuartz » Sun Jun 22, 2008 1:53 am

JQuartz wrote:so the jump from Renpy to ui and python is quite hard.
Starlightkitty7 wrote:Which is why ui has its own 'interact' coding and jump as well.
Eh...I think there's some misunderstanding here. I meant 'trying to learn ui after learning basic RenPy language' when I said 'jump'. It has nothing to do with renpy jump or ui.jump...
Jake wrote:I'm not sure why JQuartz is using the terms he is, but...

Sorry about that, it's just that I feel that one does not need to learn about ui in order to learn Python and vice versa. So personallly I tend to separate ui and python into different categories(which might or might not be a bad thing).
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Starlightkitty7
Regular
Posts: 61
Joined: Sun Jun 15, 2008 5:11 pm
Contact:

Re: Inventory Menu/Price Code

#13 Post by Starlightkitty7 » Sun Jun 22, 2008 4:46 pm

Oh I see! Sorry JQuartz, I misunderstood! ^_^

Oh I see so you can mix them together. I was curious if its possible since I started with the regular script and already coded up to # 811. ^^ That if I wanted to change later to ui it would take forever! (or soemthing) Anyways, thank you both.

Post Reply

Who is online

Users browsing this forum: Bartulisica, Bing [Bot], robcolton