Variable in Speech not Working | 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
TsugumiLightning
Newbie
Posts: 23
Joined: Sat Aug 11, 2018 5:28 am
Organization: STAY
Location: 🇦🇺
Contact:

Variable in Speech not Working | Inventory

#1 Post by TsugumiLightning »

I want to display a variable in speech but it comes up as '[inventory_text]'

Code: Select all

default inventory = ["item1", "spear", "item3"]
$ inventory_text = ', '.join(inventory)
$ turn = "Chloe"
^^ defined variables

Code: Select all

label random1:
    $ outcome = True
    "Oh! Look at that. [turn] decides to go hunting."
    "Here's your items:"
    jump list_items
    "[turn] takes the spear for hunting"
    if outcome == True:
        "[turn] comes back, but without any food."
        "[turn] decides to sleep."
    else:
        pass
    return
    
label list_items:
    "[inventory_text]"
    return
For some reason 'turn' works but not 'inventory'
Also sorry, I'm kind of new to Ren'Py so it's probably something really dumb
there are days where you cry for no reason, and today is not one of those days.

"Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference."
- Robert Frost, The Road Not Taken

User avatar
TsugumiLightning
Newbie
Posts: 23
Joined: Sat Aug 11, 2018 5:28 am
Organization: STAY
Location: 🇦🇺
Contact:

Re: Variable in Speech not Working | Inventory

#2 Post by TsugumiLightning »

Code: Select all

    $ splash_message1 = "--"
    $ splash_message2 = "--"
    $ splash_message3 = "Thank you for playing"

    image splash_warning = ParameterizedText(style="splash_text", xalign=0.5, yalign=0.5)

    label credits_splash:
        scene white
        with Dissolve(1.5)
        scene white
        show splash_warning "[splash_message1]" with Dissolve(0.5, alpha=True)
        pause 2.0
        show splash_warning "[splash_message2]" with Dissolve(0.5, alpha=True)
        pause 2.0
        show splash_warning "[splash_message3]" with Dissolve(0.5, alpha=True)
        pause 2.0
        hide splash_warning with Dissolve(0.5, alpha=True)
        return 
<Yes, I have a splashscreen for credits, I know it's not the best way to do it but at least I've coded one before so I know how to do it>

This comes up with '[splash_message1]' as well and I'm not quite sure what's happening
there are days where you cry for no reason, and today is not one of those days.

"Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference."
- Robert Frost, The Road Not Taken

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Variable in Speech not Working | Inventory

#3 Post by Remix »

When you use $ to initially set the value of variables it does not also include that variable within the store.

The general rule is always, always, always use default to set up your variables (like you did with inventory on the first line you showed)

Note: default should be outside any block, unindented .... Not in an init, not in a label...
Frameworks & Scriptlets:

User avatar
TsugumiLightning
Newbie
Posts: 23
Joined: Sat Aug 11, 2018 5:28 am
Organization: STAY
Location: 🇦🇺
Contact:

Re: Variable in Speech not Working | Inventory

#4 Post by TsugumiLightning »

Oh! I didn't know that. I was using an outdated page tho.
there are days where you cry for no reason, and today is not one of those days.

"Two roads diverged in a wood, and I—
I took the one less traveled by,
And that has made all the difference."
- Robert Frost, The Road Not Taken

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Variable in Speech not Working | Inventory

#5 Post by rames44 »

If you use a “dollar line” to set a variable that doesn’t have a “default” statement, it WILL put it in the store, but only if that line is executed during game play. Basically, you can think of that as meaning “if it’s inside a label.“ And it doesn’t get set unless the player actually traverses that line.

If you put a “dollar line” at the top of your file, not associated with a label, that line really never gets executed. (There may be “init” exceptions to this, but you don’t want to be going there, in general.)

The reason the “default” statement is so important is that if someone makes a save, and you add a “dollar line” into the script at a point before where they are when the save was made, when they resume the save, that line never gets executed. They’re already past that point. So if you were relying on that line to create the variable in the store, you now have a undefined variable, and your game goes boom later on. The “default” statement ensures that the variable is always defined, whether it was there when the save was made, or added later.

So, yes, for any variable you want to be saved, always, always include a default statement.

Post Reply

Who is online

Users browsing this forum: Google [Bot]