[Solved] random in 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
User avatar
hadoc
Newbie
Posts: 3
Joined: Sun Sep 14, 2014 7:05 am
Contact:

[Solved] random in menu

#1 Post by hadoc »

good, I wonder how I can load a random text in the game.
type array with random function and the would be text [array] ?

this is the idea (usin php)

Code: Select all


label start:

$targetArray = array("Sara","Cindy","Julie","Megan");
$rand = array_rand($targetArray);
$name = $targetArray[$rand];

    "I'll ask her... my name is [name]"



Last edited by hadoc on Fri Oct 03, 2014 9:09 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: random in menu

#2 Post by Alex »


User avatar
hadoc
Newbie
Posts: 3
Joined: Sun Sep 14, 2014 7:05 am
Contact:

Re: random in menu

#3 Post by hadoc »

Test this and works, thx.

Code: Select all

label start:
$ name = renpy.random.choice(['Sara','Cindy','Julie','Megan'])

    "I'll ask her... my name is [name]"

but, the problem is that for every time you have to make a function always have to put all text ..

Code: Select all

label start:
    $ name = renpy.random.choice(['Sara','Cindy','Julie','Megan'])

    "I'll ask her... my name is [name]"

    menu:
        $ name = renpy.random.choice(['Sara','Cindy','Julie','Megan'])
        "It's a [name].":
             jump goo
        $ name = renpy.random.choice(['Sara','Cindy','Julie','Megan'])
        "It's a [name].":
             jump muu

is there any function to optimize this? or I have to always put all code random?

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: random in menu

#4 Post by Alex »

Will putting list of names in a variable work for you?

Code: Select all

label start:
    $ name_list = ['Sara','Cindy','Julie','Megan']
    $ name = renpy.random.choice(name_list)

    "I'll ask her... my name is [name]"

    $ a = renpy.random.choice(name_list)
    $ b = renpy.random.choice(name_list)
    menu:
        "It's a [a].":
             jump goo
        "It's a [b].":
             jump muu
If not, you always can make a function (kind of examples - http://lemmasoft.renai.us/forums/viewto ... =8&t=28532, http://lemmasoft.renai.us/forums/viewto ... =8&t=28145).

User avatar
hadoc
Newbie
Posts: 3
Joined: Sun Sep 14, 2014 7:05 am
Contact:

Re: random in menu

#5 Post by hadoc »

Alex wrote:Will putting list of names in a variable work for you?

Code: Select all

label start:
    $ name_list = ['Sara','Cindy','Julie','Megan']
    $ name = renpy.random.choice(name_list)

    "I'll ask her... my name is [name]"

    $ a = renpy.random.choice(name_list)
    $ b = renpy.random.choice(name_list)
    menu:
        "It's a [a].":
             jump goo
        "It's a [b].":
             jump muu
If not, you always can make a function (kind of examples - http://lemmasoft.renai.us/forums/viewto ... =8&t=28532, http://lemmasoft.renai.us/forums/viewto ... =8&t=28145).
thx for the help.

Post Reply

Who is online

Users browsing this forum: No registered users