[SOLVED] Random name picking

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
BLucy
Newbie
Posts: 9
Joined: Tue Jun 16, 2020 5:21 am
Contact:

[SOLVED] Random name picking

#1 Post by BLucy »

Hi!

I've just started with Renpy and I was practicing option trees and I had the (back then) wonerful idea of letting one of the characters pick a name at random. Now, I looked up in Renpy's documentation and I've tryed to fix it. At first the game would show the error before starting, now it just ignores it, so I left it like this:

Code: Select all

menu nombre_hr_elige:

                "Que no, que no, solo quería ver que cara ponías, además, no sé si fiarme..." :
                    hr "hmmm"
                    jump ppnombre

                "Venga, a ver qué se te ocurre":
                    $ randomnom = renpy.random.choice([1,2,3,4,5]) # (randomize between 1 and 5)
                    if randomnom==1:
                        $ nombre_pp_hr= "Fran"
                    elif randomnom==2:
                        $ nombre_pp_hr= "Dani"
                    elif randomnom==3:
                        $ nombre_pp_hr= "AJ"
                    elif randomnom==4:
                        $ nombre_pp_hr= "Joss"
                    elif randomnom==5:
                        $ nombre_pp_hr= "Robin"
                        hr "¿Y?¿Qué te parece tu nuevo nombre, [nombre_pp_hr] Motero del Rosal Ramiro de Todos Los Santos?"
                        show hr_parp_sonrisa_animation with dissolve
                        a "¿De verdad?"

                        menu de_verdad_de_la_buena:
                            hr "Ni un apellido más ni uno menos"

                            "Porque no quiero que me confundan con Julia, que si no...":
                                hr "Bien, pues a ver si ya se te ha 'refrescado' la memoria"
                                jump ppnombre

                            "De perdidos al río ¡dámelos todos!... ¿Montero del qué?":
                                hr "[nombre_pp_hr] Montero del Rosal Ramiro de Todos Los Santos, de nada."
                                jump alt_nomb_concl
I don't know yet how random works, but I couldn't figure it out with what I found, I'm quite lost right now. It's not essential to the project, I could completly cut it out, but I'd like to know how it's done. Thank you in advance :)
Last edited by BLucy on Tue Jun 16, 2020 7:16 pm, edited 1 time in total.

Dr_arell
Regular
Posts: 70
Joined: Sun Feb 23, 2020 11:24 pm
Deviantart: DarellArt
Contact:

Re: Random name picking

#2 Post by Dr_arell »

im a noobie, but there's a function that returns a random element from a list, a element can be a name in you case, this is code i took from another post

$ randfruit = renpy.random.choice(['apple', 'orange', 'plum'])
"Shop Clerk" "Would you like a [randfruit]?"

if randfruit == 'apple':
"Shop Clerk" "Apples are in season this time of year!"
elif randfruit == 'orange':
"Shop Clerk" "They make a great garnish for cocktails!"
elif randfruit == 'plum':
"Shop Clerk" "They're not really in season, but they're always delicious!"

original post:
viewtopic.php?t=25302

BLucy
Newbie
Posts: 9
Joined: Tue Jun 16, 2020 5:21 am
Contact:

Re: Random name picking

#3 Post by BLucy »

Thanks, I'll try it! :D

BLucy
Newbie
Posts: 9
Joined: Tue Jun 16, 2020 5:21 am
Contact:

Re: Random name picking

#4 Post by BLucy »

It worked! Thank you so much @Dr_arell! Now I'm gonna see how can I make the next menu appear xd But thank you, now that I know how it's dupposed to be I can try to understand it

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]