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
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:

SOLVED: Renpy random integer and unbound random choices

#1 Post by Watercolorheart » Mon Jan 12, 2009 10:17 am

Hello, I'll see if I can be descriptive here about my problems while remaining discrete. :P

I have a variable, let's call it "A" that I sometimes need to be the equivalent of a 50%/50% coin flip, and it would be called not at the start of game, but right at that point in time.

If it's heads or 1, then an event comes to pass. If it's tails or 0, then nothing happens later and the game proceeds on normally.

Other times, I want to influence the possibility but still have it be random: 70% chance of that variable "A" being equal to one or only 25% chance.

I also have a more complicated problem. I have a certain kind of repetitive scene that needs randomness and the Hero performing the same action over and over. I want the code to pick random sentences I've already written from a set, at a certain time. So:

2 sentences from set 1 (appearance):
3 sentences from set 2 (description):
4 sentences from set 3 (dialogue):
1 sentence from set 4 (description) :


and so forth.

Can someone help me?
Last edited by Watercolorheart on Thu Jan 15, 2009 12:22 am, edited 3 times in total.
I'm not even the same person anymore

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: Slanting the odds and randomized text descriptions from set

#2 Post by JQuartz » Mon Jan 12, 2009 1:43 pm

BCS wrote:I have a variable, let's call it "A" that I sometimes need to be the equivalent of a 50%/50% coin flip, and it would be called not at the start of game, but right at that point in time.
I think you can use renpy.random.randint (1, 2). So if it's 1 it goes path A while 2 goes path B.
BCS wrote:Other times, I want to influence the possibility but still have it be random: 70% chance of that variable "A" being equal to one or only 25% chance.
For this you need to use renpy.random.randint (1, 100). So if it's 1 till 70 it goes path A while 71 till 95 goes path b.
BCS wrote:2 sentences from set 1 (appearance):
3 sentences from set 2 (description):
4 sentences from set 3 (dialogue):
1 sentence from set 4 (description) :
Well this method is quite inefficient but that's the only way I could think of. First you need to put ifs for each sentence like so:

Code: Select all

if B==1:
    "This is sentence 1"
Then when the choice is made, put the variable with the appropriate value so that only the selected sentences are run.
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
monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Slanting the odds and randomized text descriptions from set

#3 Post by monele » Mon Jan 12, 2009 2:06 pm

For the last problem, assuming I understand what you're going for, this might be useful :
http://renpy.org/wiki/renpy/doc/referen ... dom.choice

Basically, you create a list of elements, and have Ren'Py pick one randomly... if you need this done twice, you just call it twice, with a random result each time (repeats might occur though!). If you really need no repeats... well... we'll see then :)

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: Slanting the odds and randomized text descriptions from set

#4 Post by Watercolorheart » Mon Jan 12, 2009 2:46 pm

You know, I've said it before but I'll say it again ... you guys are GREAT and so helpful. Those first two suggestions, and I think I can work in that last one. It may be a little unwieldly, though.

Can you do that line of code and have it wrap around multiple times without it breaking? I know I have one set with around 100 unique descriptions ... well, I'll just have to make a test script and see with only that portion before I dump it into my main game.

How would I call this for a statement?

"Wow, she looks __randomappearance___ !"

$ randomappearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'])
I'm not even the same person anymore

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: Slanting the odds and randomized text descriptions from set

#5 Post by JQuartz » Mon Jan 12, 2009 3:03 pm

BCS wrote:How would I call this for a statement?

"Wow, she looks __randomappearance___ !"

$ randomappearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'])
Like so

Code: Select all

$ randomappearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'])

"Wow, she looks %(randomappearance)s!"
BCS wrote:Can you do that line of code and have it wrap around multiple times without it breaking?
I don't get what you mean...
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: Slanting the odds and randomized text descriptions from set

#6 Post by Watercolorheart » Mon Jan 12, 2009 4:50 pm

JQuartz wrote:"Wow, she looks %(randomappearance)s!"
Great, so that's how. :mrgreen: :mrgreen:
BCS wrote:Can you do that line of code and have it wrap around multiple times without it breaking?
I don't get what you mean...

Code: Select all

     $ randomappearance = renpy.random.choice(['stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff']) 
I'm not even the same person anymore

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: Slanting the odds and randomized text descriptions from set

#7 Post by JQuartz » Mon Jan 12, 2009 4:58 pm

BCS wrote:

Code: Select all

$ randomappearance = renpy.random.choice(['stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff','stuff', 'stuff'])
Eh...you answered your own question.
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: Slanting the odds and randomized text descriptions from set

#8 Post by Watercolorheart » Tue Jan 13, 2009 12:57 pm

Hmm, I was on the wiki trying to see how to assign it to a particular variable using random.integer and it looks like the Example is bugged. =(!

http://renpy.org/wiki/renpy/doc/referen ... om.randint

I was trying to see how to assign it to something. This is the little code I wrote, I'm about to test it.

Code: Select all

$ baby = renpy.random.randint (1, 100)
if baby >= 71:
    jump pregnant
if baby <= 70:
    jump notpregnant
label pregnant:
"Looks like you're going to be a proud father! =D"

label notpregnant:
"Looks like you didn't make a baby this time. D="
"Try again!"
Last edited by Watercolorheart on Tue Jan 13, 2009 1:03 pm, edited 1 time in total.
I'm not even the same person anymore

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Slanting the odds and randomized text descriptions from set

#9 Post by PyTom » Tue Jan 13, 2009 1:01 pm

You'd have to call it, otherwise you're just assigning the function itself to a variable. Something like:

$ B = renpy.random.randint(1, 10)

assigns B a random integer between 1 and 10, inclusive.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

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: Slanting the odds and randomized text descriptions from set

#10 Post by Watercolorheart » Tue Jan 13, 2009 1:04 pm

Can we get that example up on the wiki fixed so someone like me doesn't run into that same problem?

Man, I may be a good artist but I am no programmer ... if the solution isn't obvious, then I usually just make something hacky.
I'm not even the same person anymore

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: Slanting the odds and randomized text descriptions from set

#11 Post by Watercolorheart » Tue Jan 13, 2009 1:07 pm

Okay, it tested beautifully and that wraps up this problem. =)
I'm not even the same person anymore

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: FIXED: Renpy random integer and random choices

#12 Post by Watercolorheart » Tue Jan 13, 2009 1:36 pm

Ergh, with just this line of code we were using ...

Code: Select all

" %(randomstopgap)s "
$ randomappearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'])
I'm getting this description, but no official traceback error. But the text says:

"randomstopgap unbound"

[/edit]

Face, meet palm.


" %(random stopgap )s "
$ random appearance = renpy.random.choice(['cute', 'slender', 'fit', 'pretty', 'buxom'])

[//edit]

Man, I am ready to tear my hair out by its ROOTS!! That wasn't it! I changed both to the exact same name, and it's still unbound.
I'm not even the same person anymore

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Renpy random integer and unbound random choices

#13 Post by PyTom » Tue Jan 13, 2009 1:53 pm

Where is the wiki wrong?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

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

#14 Post by Watercolorheart » Tue Jan 13, 2009 2:01 pm

That's strange, it gave me a bogus message just a while ago ... damn, I should have taken a screenshot. I thought it was repeatable. It was something about a missing CSS tag and then it listed a lot of available programming languages.
I'm not even the same person anymore

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

#15 Post by Watercolorheart » Tue Jan 13, 2009 2:28 pm

Is it possible to include dialogue and a short seriesusing renpy.random.choice or include another renpy.random.choice inside the original renpy.random.choice?

I tried '\"Person\" \"Hey!\"' but it didn't seem to like that ... it just displays "Person" "Hey!" and that isn't correct. "Person" should be in the name field. :/

I also can't seem to call something that refers to

Code: Select all

    $ l = Character('You', color="#c8ffc8")
from within it, and that's going to be a major problem for me. It seems like this code is too limited for what I have in mind.

I also have a few that would not be suitable with a {w} or {p} tag, but actually need to break and follow in a series. I'm not sure how to handle that from within a little list like that, or call to a specific label.

For example, a couple of them are random quips. So it would still be in the random list, but would look something like

Code: Select all

"Person" "?"
"You" "!"
to the player.

I'm trying to figure out if the {nw} tag would work ... basically, what I need is something like {p} or {w} but actually erases the first line and displays the next one ...

I also can't call another %(randompronoun1)s from within the first %(randomstopgap)s ... this is going to be a BIG problem. D:
I'm not even the same person anymore

Post Reply

Who is online

Users browsing this forum: No registered users