changing chance

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
Lion
Newbie
Posts: 21
Joined: Tue Mar 08, 2011 7:49 pm
Contact:

changing chance

#1 Post by Lion »

yo
so, i really want to add a random factor into my new experiment.
the thing is, i want an option to be "eresed" from the chance factor once it was used.
(once it become True, the random factor will not use it in the chance)
how it would be physically?
you spin a rollete and win an appel for example, in the spins after that, you wont be able to win an 'apple' anymore.

im used to this code

Code: Select all

$ event = renpy.random.choice (['grape', 'strawberry', 'orange', 'appel'])
    
and i could write an "if" stetment for every 'event' but that makes 4*3*2*1=24 "if" stetments (and that just in an example with only 4 choices, its sceary to even think about what will happen with more chocies)

so is there a way to include the "if False" into the code and not reach 24 lines of coding?

i tried doing something like this (but faild unfortunatly):

Code: Select all

$ event = renpy.random.choice ([('grape', if False), ('strawberry', if False),  ('orange', if false), ('appel', if false)])
    
so... ideads anyone?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: changing chance

#2 Post by PyTom »

The best way to do this is to remove items from the list once they're used.

Code: Select all

    $ flavors = ['grape', 'strawberry', 'orange', 'apple' ]

label repeat:

    if not flavors:
        jump done

    $ event = renpy.random.choice(flavors)
    $ flavors.remove(event)

    ....
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Lion
Newbie
Posts: 21
Joined: Tue Mar 08, 2011 7:49 pm
Contact:

Re: changing chance

#3 Post by Lion »

who awsome!!! thenk you!!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]