Can't call [variables] in a string given by renpy.random.choice() and can't show dialogue during menu

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
Chandrakanta
Newbie
Posts: 2
Joined: Fri Oct 19, 2018 11:31 pm
Contact:

Can't call [variables] in a string given by renpy.random.choice() and can't show dialogue during menu

#1 Post by Chandrakanta »

Hello, I'm completely new, first post.

I'm trying to have a character say randomly chosen lines of dialogue while the player is naming themselves, but run into 2 issues.

1) I can't have a menu show dialogue and a choice if I have something else besides dialogue in the menu like this:

Code: Select all

label start:
    e "You've created a new Ren'Py game."
    $ vartest = 1
    if vartest == 1:
        e "vartest is 1"
label question:
    menu:
        if vartest == 1:
             e "Is this text is displayed while the menu choices are visible?"
        elif vartest == 2:
            e "this is alternative text that can be chosen to be displayed during the menu"
        #e "this is the normal position to show dialogue while menu choices are visible."
        "Yes":
            e "Okay."
            jump Continue
        "No":
            e "Oh? what went wrong?"
            jump question
label Continue:
    e "the game continues after"
I get the error: Parsing the script failed. - File "game/script.rpy", line 19: expected menuitem ->if vartest == 1:

2) I am having trouble showing variables properly from renpy.random.choice([]) when they are inside the choices ...uhh like this:

Code: Select all

$ name = "john"
$ randomtalk = renpy.random.choice(["Are you [name] then?", "You're [name]?"])
e "[randomtalk]"
will display dialogue like "Are you [name] then?" instead of what I wanted; "Are you John then?"

Ideally I wanted to combine the both to generate random dialogue while the menu is showing (and also have a lot more dynamic dialogue during the rest of the game) but I don't know if I am going about these the correct way, if there is a simpler way to do these, or if it just isn't possible without doing something too complicated for a beginner.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Can't call [variables] in a string given by renpy.random.choice() and can't show dialogue during menu

#2 Post by Per K Grok »

Chandrakanta wrote: Sat Oct 20, 2018 12:30 am Hello, I'm completely new, first post.

I'm trying to have a character say randomly chosen lines of dialogue while the player is naming themselves, but run into 2 issues.

-----
try this

Code: Select all

label question:

    if vartest == 1:
        $ eString = "Is this text is displayed while the menu choices are visible?"

    elif vartest == 2:
        $ eString = "this is alternative text that can be chosen to be displayed during the menu"


    menu:

        e "[eString]"
        "Yes":
            e "Okay."
            jump Continue
        "No":
            e "Oh? what went wrong?"
            jump question

label Continue:
    e "the game continues after"

    $ name = "john"
    $ randomtalk = renpy.random.choice(["Are you " + name + " then?", "You're " + name + "?"])
    e "[randomtalk]"




Chandrakanta
Newbie
Posts: 2
Joined: Fri Oct 19, 2018 11:31 pm
Contact:

Re: Can't call [variables] in a string given by renpy.random.choice() and can't show dialogue during menu

#3 Post by Chandrakanta »

Per K Grok wrote: Sat Oct 20, 2018 2:26 am try this
Hello Per K Grok, those solutions are interesting and I will certainly remember them.
This

Code: Select all

$ randomtalk = renpy.random.choice(["Are you " + name + " then?", "You're " + name + "?"])
    e "[randomtalk]"
part solves all of my problems here, I didn't know how to add a variable to a string like that and I can also use it for the starting menu dialogue! (by putting the renpy.random.choice just outside the menu block, and the e"[randomtalk]" as the menu dialogue.)

Thank you very much for your prompt help.

Elise269
Newbie
Posts: 1
Joined: Mon Jun 10, 2019 5:12 am
Tumblr: renpytom
Deviantart: renpytom
Github: renpytom
Skype: renpytom
Soundcloud: renpytom
itch: renpytom
Contact:

Re: Can't call [variables] in a string given by renpy.random.choice() and can't show dialogue during menu

#4 Post by Elise269 »

this is very informative and intersting for those who are interested in blogging field cleanmaster

Post Reply

Who is online

Users browsing this forum: Google [Bot], Imperf3kt