Page 1 of 4
SOLVED: Renpy random integer and unbound random choices
Posted: Mon Jan 12, 2009 10:17 am
by Watercolorheart
Hello, I'll see if I can be descriptive here about my problems while remaining discrete.
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?
Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 1:43 pm
by JQuartz
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:
Then when the choice is made, put the variable with the appropriate value so that only the selected sentences are run.
Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 2:06 pm
by monele
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

Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 2:46 pm
by Watercolorheart
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'])
Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 3:03 pm
by JQuartz
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...
Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 4:50 pm
by Watercolorheart
JQuartz wrote:"Wow, she looks %(randomappearance)s!"
Great, so that's how.
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'])
Re: Slanting the odds and randomized text descriptions from set
Posted: Mon Jan 12, 2009 4:58 pm
by JQuartz
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.
Re: Slanting the odds and randomized text descriptions from set
Posted: Tue Jan 13, 2009 12:57 pm
by Watercolorheart
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!"
Re: Slanting the odds and randomized text descriptions from set
Posted: Tue Jan 13, 2009 1:01 pm
by PyTom
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.
Re: Slanting the odds and randomized text descriptions from set
Posted: Tue Jan 13, 2009 1:04 pm
by Watercolorheart
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.
Re: Slanting the odds and randomized text descriptions from set
Posted: Tue Jan 13, 2009 1:07 pm
by Watercolorheart
Okay, it tested beautifully and that wraps up this problem. =)
Re: FIXED: Renpy random integer and random choices
Posted: Tue Jan 13, 2009 1:36 pm
by Watercolorheart
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.
Re: Renpy random integer and unbound random choices
Posted: Tue Jan 13, 2009 1:53 pm
by PyTom
Where is the wiki wrong?
Re: Renpy random integer and unbound random choices
Posted: Tue Jan 13, 2009 2:01 pm
by Watercolorheart
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.
Re: Renpy random integer and unbound random choices
Posted: Tue Jan 13, 2009 2:28 pm
by Watercolorheart
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
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: