SOLVED: Renpy random integer and unbound random choices

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.
Message
Author
User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#46 Post by JQuartz » Wed Jan 14, 2009 7:36 pm

Well I know of a roundabout way but as usual it's inefficient so use it at your own discretion. Here an example of the code:

Code: Select all

label first_value:
    $ value1=renpy.random.choice([1, 2, 3])
label second_value:
    $ value2=renpy.random.choice([1, 2, 3])
    if value1==value2:
        jump second_value
label third_value:
    $ value3=renpy.random.choice([1, 2, 3])
    if value1==value3 or value2==value3:
        jump third_value
This code will ensure all the values you get are different but it's a big mess if you intend to use 1000s of choices.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Renpy random integer and unbound random choices

#47 Post by Showsni » Wed Jan 14, 2009 7:52 pm

BCS wrote:I wonder if there is any way to prevent a random container from selecting the same thing twice ... ?
Try using remove.

Code: Select all

    $ squiggle = [1, 2, 3, 4, 5]
    label abc:
        pass
    
    
    $ mychoice = renpy.random.choice(squiggle)
    
    "You chose %(mychoice)s."
    $ squiggle.remove(mychoice)
    jump abc
It gives an error once you've run out of choices, though.

Similarly, append adds things to lists.

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Renpy random integer and unbound random choices

#48 Post by JQuartz » Wed Jan 14, 2009 8:08 pm

Showni way is better if you don't plan to have choices that have been chosen be chosen again. Showsni method is less messy and more efficient than mine.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

Watercolorheart
Eileen-Class Veteran
Posts: 1314
Joined: Mon Sep 19, 2005 2:15 am
Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
Organization: Watercolorheart Studios
IRC Nick: BCS
Tumblr: adminwatercolor
Deviantart: itsmywatercolorheart
Github: Watercolordevdev
Skype: heartnotes
Soundcloud: Watercollider
itch: watercolorheart
Location: Florida
Contact:

Re: Renpy random integer and unbound random choices

#49 Post by Watercolorheart » Wed Jan 14, 2009 10:13 pm

Hmm, well, I'll definitely try it out in the future! :P I'll probably test it on Serkai's Zelda dungeon-style puzzles he's helping me with. A bit of randomness in descriptions for something like mirrors and walls and floors and rooms (atmosphere, anyway?) would alleviate some of the monotony too.
I'm not even the same person anymore

User avatar
Dusty
Regular
Posts: 126
Joined: Fri Jul 25, 2008 11:51 pm
Contact:

Re: Renpy random integer and unbound random choices

#50 Post by Dusty » Thu Jan 15, 2009 12:19 am

BCS wrote:
Jake wrote:
BCS wrote:Got it. Thanks. Delete it, roll again, right?
You don't even need to delete it, really - just assign a new value over the top and it'll replace what was already there. The distinction is just that the variable will always contain whatever value it was last given, and can't go off and find a new random number on its own - you have to explicitly generate and assign a new random number each time you want it to change.
I think I "got" it by the time I reached the end of my script, instead of copying and pasting gobs of text over. You can use a "call" function to accomplish this repeatedly, right?
Whoops. Yeah, when I was talking about "del" that wasn't the thing I was trying to get across. :D

Sorry for confusing you.

User avatar
squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: SOLVED: Renpy random integer and unbound random choices

#51 Post by squark » Fri Apr 06, 2012 1:30 pm

Okay, I've been all over this thread and it seems like the place to post this.
I've got a question about the random integer generator, but I need it to be reusable, and creating new generators doesn't seem to be too efficient in this regard. Basically it's going to be used for meeting random people while out exploring.
I have this set up in my script file:

Code: Select all

label start:
   (flags and stuff)
   $ go_diceroll = renpy.random.randint(1, 8)
I've set up the first call like so in a seperate script:

Code: Select all

label explore:
   if go_diceroll = (value):
      show (person)
   elif (blah blah blah)
And it basically stacks like that.
As you can imagine setting up another generator for every single one of these will not only be cumbersome, but very time consuming and horribly inefficient. Is there any way to cause my dice to "forget" its original result and roll another one once I need it to?
I did read Showsni's choice system, but doesn't seem to be the way I want to take this.

One last thing.
Depending on how the player interacts with certain NPCs I'd like the dice weighted in favour of that NPC, or less likely to meet as the case may be. This makes it sound like a Dating Sim, but it's not.

Any help is greatly appreciated.

EDIT: I've looked again and it seems kind of handy. But I'd still like an easy to use weighting system.
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
Altsune
Newbie
Posts: 14
Joined: Tue Mar 25, 2014 10:57 pm
Completed: Let's go! Hiragana, Let's go! Katakana, Let's go! Hangul
Organization: Madame Motoko
Github: https://github.com/MadameMotoko
itch: Motoko
Location: Pittsburgh, PA
Contact:

Re: SOLVED: Renpy random integer and unbound random choices

#52 Post by Altsune » Tue Sep 16, 2014 3:28 am

I know I'm a few years late to the party, but this helped me a ton!

Post Reply

Who is online

Users browsing this forum: No registered users