How to repeat a random event but get a different outcome?(SOLVED)

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
izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

How to repeat a random event but get a different outcome?(SOLVED)

#1 Post by izuma » Sun Aug 18, 2019 4:15 pm

I'm making a small "Gacha" game where the game basically randomly chooses a picture from a pool of pictures and the player gets to roll again to get another picture. I've been told that using the random.randint(x,y) instead of the renpy.random.randint(x,y) would get me the results I want but I found that it would still give me the same result if I jumped back to the label where it's meant to play. I'm not sure if this is a case of me not putting the code in the right place but I'll list out what I've got (somewhat abridged).

Code: Select all

label start:
    default pink = 1
    default blue = 1
    default yellow = 1
    $ pink = random.randint(1, 5)
    $ blue = random.randint(1, 4)
    $ yellow = random.randint(1, 5)
And then I had labels pink, blue, and yellow that had the spinner values indicated like this.

Code: Select all

label pink:
    show bg gachaP with fade
    b "Hurray!"
    b "Twist the knob and see what you get!"
    if pink==1:
        $ persistent.unlock_1 = True        
        show p_open
        pause 2
        hide p_open with dissolve
        show P01 at middle with dissolve
        b "woohoo"
        b "Would you like to play again?"
        hide P01 with dissolve
        menu:
            "Yes!":
                b "Hurray! Stay on this machine or pick a new one?"
                menu: 
                    "New one":
                        jump choose
                    "Stay with Pink":
                        jump pink
            "No!":
                b "Ok, no problem! Hope to see you again real soon!"
                return
This would be the same for all of the values (inefficient I know)((Middle here is a custom transform btw so no worries there)). But yeah, if anyone has an idea to help me with this repeat problem, let me know! If you need more code from me too, let me know but there's not much variety past this really.
Last edited by izuma on Thu Aug 22, 2019 10:26 pm, edited 1 time in total.

User avatar
Angelo Seraphim
Regular
Posts: 32
Joined: Tue May 21, 2019 8:00 am
Completed: Enamored Risks (NaNoReNo 2020)
Projects: 616 Charagma
Organization: GLSUoA
Deviantart: glsuoa
itch: glsuoa
Location: London, UK
Discord: Just A Concept#9599
Contact:

Re: How to repeat a random event but get a different outcome?

#2 Post by Angelo Seraphim » Mon Aug 19, 2019 5:05 am

In order to get a different number generated after each interaction, you may need to add:

Code: Select all

    $ pink = renpy.random.randint(1, 5)
    $ blue = renpy.random.randint(1, 4)
    $ yellow = renpy.random.randint(1, 5)
... somewhere (probably after or before jump/label.) That will make it generate another random number.

So for instance:

Code: Select all

default pink = 0
label start:
    $ pink = renpy.random.randint(1, 100) # Will generate a random number
    "Pink is now [pink]."
    $ pink = renpy.random.randint(1, 100) # Will generate another random number when this point is reached
    "Pink is now [pink]."
# and so on.
Also, you should default your variables outside of a label. So those "defaults" should go before the label and, of course, use "$" to change/update the variable inside the label.

(Edited)
Image

User avatar
Angelo Seraphim
Regular
Posts: 32
Joined: Tue May 21, 2019 8:00 am
Completed: Enamored Risks (NaNoReNo 2020)
Projects: 616 Charagma
Organization: GLSUoA
Deviantart: glsuoa
itch: glsuoa
Location: London, UK
Discord: Just A Concept#9599
Contact:

Re: How to repeat a random event but get a different outcome?

#3 Post by Angelo Seraphim » Tue Aug 20, 2019 2:48 pm

Sorry, one more thing to note.
If you want to use 'random.randint(1, 100)' you need to import random or else you'd get an error.
Another, thing to note is the difference between 'random.randint' and 'renpy.random.randint.'
---

Code: Select all

init python:
    import random  # You need to add this to use 'random.randint()'

default a = random.randint()  # - Is not stored and will change through rollback.
default b = renpy.random.randint()  # - Is stored and will always produce the same result through rollback.
---
(edit) Sorry for the double post. :mrgreen:
Image

izuma
Newbie
Posts: 6
Joined: Fri Mar 06, 2015 12:00 pm
Contact:

Re: How to repeat a random event but get a different outcome?

#4 Post by izuma » Thu Aug 22, 2019 10:25 pm

After some finagling, it's working! Thank you so much!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]