How to make the first line of a menu dynamic?

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
jacob_ax
Regular
Posts: 32
Joined: Thu Jan 31, 2019 9:21 am
Contact:

How to make the first line of a menu dynamic?

#1 Post by jacob_ax »

Hi everyone,
I'm trying to make something like this:

Code: Select all

define bman = Character("Bartender")
$ number = renpy.random.randint(1,3)

menu ask_for_a_drink:
	
	#First we have three condition that will decide what will appear in the textbox (the bartender is talking)
	if number == 1:
		bman "What's your poison?"
	if number == 2:
		bman "You thirsty?"
	if number == 3:
		bman "What would you like today?"
	
	#Then the choices that will appear on the menu screen
	"Vodka":
		some text and actions...
	"Jin":
		some text and actions...
	"Wine":
		some text and actions...
the problem is, this doesn't work. Is there a way to deal with this?
Thanks :)

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: How to make the first line of a menu dynamic?

#2 Post by DannX »

You could try this:

Code: Select all

    # A list with possible greetings for the bartender
    $ bman_texts = ["What's your poison?", "You thirsty?", "What would you like today?"]

    # pick one of them with renpy.random.choice and store it in a variable called t 
    $ t = renpy.random.choice(bman_texts)

    menu ask_for_a_drink:

        bman "[t]" #have bman character speak the selected text

        "Vodka":
            # some text and actions
            pass
        "Jin":
            # some text and actions
            pass
        "Wine":
            # some text and actions
            pass    
With renpy.random.choice, the game randomly selects one element from a list, in this case, one string of text. Then you interpolate it with [] in renpy dialogue. This saves typing since you don't need randint and a lot of if statements.

jacob_ax
Regular
Posts: 32
Joined: Thu Jan 31, 2019 9:21 am
Contact:

Re: How to make the first line of a menu dynamic?

#3 Post by jacob_ax »

Thanks!!!
:D

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]