Random Event Scene

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
georgewbush
Newbie
Posts: 13
Joined: Fri Nov 30, 2018 5:14 pm
Contact:

Random Event Scene

#1 Post by georgewbush »

Hi, I searched on the forum for a solution but they didn't work. What I am looking for is something like this:

Code: Select all

$ choice = renpy.random.choice(("pon", "ken", "jan"))
    
    if choice == "jan":
        "Jan!"
    elif choice == "ken":
        "Ken!"
    elif choice == "pon":
        "Pon!"
I use that code, but it ALWAYS shows "jan" as the random choice. Basically the last choice in the renpy choice list gets chosen.

I figure the code is out of date.

Are there any working codes to randomize a scene?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Random Event Scene

#2 Post by Imperf3kt »

Havent got time to look into it properly, but I think "choice" is one of the renpy reserved words.
Try using a different word.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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: Random Event Scene

#3 Post by Remix »

renpy.random.choice is designed to work with rollback/forward so it actually stores and remembers the random value

It would *potentially* choose a different value if you started a new game
Frameworks & Scriptlets:

georgewbush
Newbie
Posts: 13
Joined: Fri Nov 30, 2018 5:14 pm
Contact:

Re: Random Event Scene

#4 Post by georgewbush »

Ok then that choice is no use for me because I need it to be random whenever it is called. I want to rollback and each time be a random scene not have to start a new game to see the other choices be picked.

Any new code for such a thing?

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Random Event Scene

#5 Post by IrinaLazareva »

Code: Select all

init python: 
    from random import choice
label start:
    '?'
    $ mchoice = choice(["Pon", "Ken", "Jan"])
    "[mchoice]!"
https://docs.python.org/release/2.3.4/l ... andom.html
https://renpy.org/doc/html/other.html#renpy-random

georgewbush
Newbie
Posts: 13
Joined: Fri Nov 30, 2018 5:14 pm
Contact:

Re: Random Event Scene

#6 Post by georgewbush »

Thanks guys for your help! This forum rocks!

Post Reply

Who is online

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