%(money)d display in inventory

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
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

%(money)d display in inventory

#1 Post by Bartulisica »

In dialogue, I can show my "money" value with %(money)d command, but if I want to add the same text to inventory
screen, it just says "You have %(money)d". Literally.
What seems to be the problem here. Money not defined in the right place? Coz I define it after label start, and inv_screen is defined before. How to fix this?
And, how to show item list? %(items)d isn't working as well. ( $ items = [])

Code: Select all

screen inv_screen:
             frame:
                 vbox:
                      text "Inventory: "
                      text "You have %(money)d"
I know I have so much questions, but I'm pretty new to Ren'Py, and even though I get the basics, and I know enough to make a simple VN, I want to explore more.

Thanks in advance.
- ArizonaIdentities

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: %(money)d display in inventory

#2 Post by mobychan »

Code: Select all

screen inv_screen:
    frame:
        vbox:
            text "Inventory: "
            text "You have %d" % (money)
this should do the trick

since your items variable is an array you need to loop that array and add each item as text:

Code: Select all

for item in items:
    text item

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: %(money)d display in inventory

#3 Post by trooper6 »

Renpy text interpolation uses brackets, so as long as you are in a Renpy line rather than a python line, you don't have to use %

Here is an inventory screen that I made as an example for someone else that shows both an individual variable and a list:

Code: Select all

default gold = 100
default items = ["rope", "dagger", "chewing gum"]

screen inventory_screen():
    vbox:
        align (0.9, 0.0)
        text "Inventory:"
        text "_____"
        text "Gold Pieces: [gold]"
        for item in items:
            text "[item]"

label start:
    show inventory_screen()
    "You should see your inventory in the upper right corner."
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

Dylan
Newbie
Posts: 9
Joined: Sat Aug 01, 2015 6:23 pm
Location: U.S.
Contact:

Re: %(money)d display in inventory

#4 Post by Dylan »

Instead of writing $ in front of the variables instead type define so it looks something like this (borrowing your example mobychan):

Code: Select all

define items = ["apple", "phone"]
define money = 0

##########
screen inv_screen:
    frame:
        vbox:
            text "Inventory: "
            text "You have %d" % (money)
            for item in items:
                text item
        
    
# The game starts here.
label start:
    show screen inv_screen()
    "Menu screen on top left."
    "End game."
    return

trooper6, you forgot to put "screen" for "show screen"

Code: Select all

label start:
    show screen inventory_screen()
    "You should see your inventory in the upper right corner."

User avatar
Bartulisica
Regular
Posts: 93
Joined: Sun Aug 30, 2015 5:11 am
Organization: ArizonaIdentities
Location: Croatia
Discord: ArizonaIdentities
Contact:

Re: %(money)d display in inventory

#5 Post by Bartulisica »

@ mobychan : I tried to do so before I posted the question, and it didn't work..

But, thanks all of you!
- ArizonaIdentities

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: %(money)d display in inventory

#6 Post by trooper6 »

Dylan wrote:Instead of writing $ in front of the variables instead type define so it looks something like this (borrowing your example mobychan):

Code: Select all

define items = ["apple", "phone"]
define money = 0
not define, default

It should be
default items = ["apple", "phone"]
Dylan wrote: trooper6, you forgot to put "screen" for "show screen"
So I did! Thanks for catching that error!
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

Dylan
Newbie
Posts: 9
Joined: Sat Aug 01, 2015 6:23 pm
Location: U.S.
Contact:

Re: %(money)d display in inventory

#7 Post by Dylan »

Thanks, didn't realize there was a difference since I was getting the same output.
Guess I need to re-read the documentation a bit more thoroughly.

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: %(money)d display in inventory

#8 Post by trooper6 »

Default and define are both described one after another here: http://www.renpy.org/doc/html/python.ht ... -statement

The seem very similar and I think PyTom would have to explain all the differences. What I'd say is that I've generally seen define used primarily with characters...which don't change after init. On the other hand, I see default used for variables that are changed during the course of the game.
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
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: %(money)d display in inventory

#9 Post by PyTom »

Bracket interpolation is now always preferred to %(whatever)d interpolation, which has been left around to support legacy code. Bracket interpolation works everywhere text does, and code like:

Code: Select all

text "Hello, [planet]."
is much faster than

Code: Select all

text "Hello, %s." % planet
since it can be more easily analyzed by Ren'Py.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot], Sugar_and_rice