[Solved] renpy.random.randint is picking the same variable every time? How to fix it?

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
User avatar
lacrimoosa
Newbie
Posts: 23
Joined: Tue Jun 05, 2018 8:31 pm
Projects: Alice's Reverie
Organization: Red&Pink games
Tumblr: lacrimoosa, alicesreverie
itch: redpink-games
Contact:

[Solved] renpy.random.randint is picking the same variable every time? How to fix it?

#1 Post by lacrimoosa »

I want to make a blinking animated sprite, but instead of using a set amount of time between the times that it blinks, I was wondering if it was possible to have a random number generator determine how often they blink.

I've tried using renpy.random like this:

Code: Select all

image blink:
    "open.png"
    renpy.random.randint(0, 3)
    "half.png"
    .05
    "close.png"
    .05
    "half.png"
    .05
    repeat
but it seems to always choose 3 seconds before replaying the animation.

Is there a better way to accomplish what I'm trying to do or am I just inputting the renpy.random wrong?
Last edited by lacrimoosa on Thu Dec 13, 2018 11:28 pm, edited 1 time in total.
Image

An artist/writer/programmer working to get mine and my partner's ideas out into the world through Red & Pink Games!
"Oh geez, looks like the code just broke."

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

Re: renpy.random.randint is picking the same variable every time? How to fix it?

#2 Post by Imperf3kt »

I cant comment at the moment about how to code this, but I felt it is worth mentioning that you may want to randomise between at least 1 and 3, instead of 0 and 3. Otherwise you could end up with something very out of place,, such as super slow blinking, where it seems the character will never blink (if randint gets 0 all the time, the blink will constantly try to play from the beginning, but never actually show because randint gets another 0 and tries to restart the animation) .
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
lacrimoosa
Newbie
Posts: 23
Joined: Tue Jun 05, 2018 8:31 pm
Projects: Alice's Reverie
Organization: Red&Pink games
Tumblr: lacrimoosa, alicesreverie
itch: redpink-games
Contact:

Re: renpy.random.randint is picking the same variable every time? How to fix it?

#3 Post by lacrimoosa »

Thank you, I had no idea that was a thing that could happen! That would've been a lil catastrophic.

unfortunately, with "renpy.random.randint(0, 3)", it still doesn't seem to change the time between animations :(
Image

An artist/writer/programmer working to get mine and my partner's ideas out into the world through Red & Pink Games!
"Oh geez, looks like the code just broke."

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: renpy.random.randint is picking the same variable every time? How to fix it?

#4 Post by Remix »

Code: Select all

image blink:
    "open.png"
    choice:
        pause 1.2
    choice:
        pause 3.7
    choice:
        pause 4.8
    "half.png"
    pause 0.1
    repeat
Frameworks & Scriptlets:

User avatar
lacrimoosa
Newbie
Posts: 23
Joined: Tue Jun 05, 2018 8:31 pm
Projects: Alice's Reverie
Organization: Red&Pink games
Tumblr: lacrimoosa, alicesreverie
itch: redpink-games
Contact:

Re: renpy.random.randint is picking the same variable every time? How to fix it?

#5 Post by lacrimoosa »

Remix wrote: Thu Dec 13, 2018 10:48 pm

Code: Select all

image blink:
    "open.png"
    choice:
        pause 1.2
    choice:
        pause 3.7
    choice:
        pause 4.8
    "half.png"
    pause 0.1
    repeat
Thank you! That was exactly what I was looking for!
Image

An artist/writer/programmer working to get mine and my partner's ideas out into the world through Red & Pink Games!
"Oh geez, looks like the code just broke."

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: [Solved] renpy.random.randint is picking the same variable every time? How to fix it?

#6 Post by rames44 »

In your original code, I very strongly suspect that Ren’py only evaluated the call to random once - at the point where it processed the ATL logic and transformed it into the internal Python classes that it uses under the hood. In other words, when Ren’py tunes your rpy file into an rpyc file, it evaluated the random call at that point, got 3, and then proceeded as if you’d coded a 3 there. I’m betting this is exactly why ATL has the “choice” construct.

User avatar
lacrimoosa
Newbie
Posts: 23
Joined: Tue Jun 05, 2018 8:31 pm
Projects: Alice's Reverie
Organization: Red&Pink games
Tumblr: lacrimoosa, alicesreverie
itch: redpink-games
Contact:

Re: [Solved] renpy.random.randint is picking the same variable every time? How to fix it?

#7 Post by lacrimoosa »

Yeah, that sounds about right. When I was testing out the original code, it would always choose 3 and I mean always. And while "choice" does get the job done in letting me have a set of variables for the code to pick from at random, I was originally hoping that I would be able to make the game choice it's own random number between a set of integers down the selecting random decimal points. For now, "choice" works, but if there's a way to do what I was trying to do with "renpy.random", then I would rather use that.
Image

An artist/writer/programmer working to get mine and my partner's ideas out into the world through Red & Pink Games!
"Oh geez, looks like the code just broke."

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: [Solved] renpy.random.randint is picking the same variable every time? How to fix it?

#8 Post by rames44 »

Well, one way to do it would be a custom Displayable.
https://www.renpy.org/doc/html/udd.html
You have pretty much complete control as to what’s displayed. This one would be a pretty simple one to code.

User avatar
lacrimoosa
Newbie
Posts: 23
Joined: Tue Jun 05, 2018 8:31 pm
Projects: Alice's Reverie
Organization: Red&Pink games
Tumblr: lacrimoosa, alicesreverie
itch: redpink-games
Contact:

Re: [Solved] renpy.random.randint is picking the same variable every time? How to fix it?

#9 Post by lacrimoosa »

rames44 wrote: Mon Dec 24, 2018 1:00 pm Well, one way to do it would be a custom Displayable.
https://www.renpy.org/doc/html/udd.html
You have pretty much complete control as to what’s displayed. This one would be a pretty simple one to code.
This looks a bit complicated for my python skills at the moment, but I'll have to try it when I learn a little more about object-oriented coding!
Image

An artist/writer/programmer working to get mine and my partner's ideas out into the world through Red & Pink Games!
"Oh geez, looks like the code just broke."

Post Reply

Who is online

Users browsing this forum: bloodzy