Different random after scroll back

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
hapciupalit
Newbie
Posts: 20
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Different random after scroll back

#1 Post by hapciupalit » Tue Feb 25, 2020 9:41 am

I'm building a roulette and I'm trying to generate a random number. My problem right now is that if I scroll back then I know what number is going to be.
This is my code right now. Is there a way to generate different number even if I scroll back, cuz the other solution would be to stop the scroll, which I don't really want, but if there is no other way, I'll do it.

Code: Select all

label casino_roulette_spin:
    scene image ("gui/casino/rlt_background.png")
    "Roulette spining"

    $rlt_drop = renpy.random.randint(0, 37)

    "It's a [rlt_drop]"

    jump casino_roulette
    

briarbun
Regular
Posts: 48
Joined: Wed Feb 20, 2019 4:23 pm
Projects: Helix Felix
Location: PNW
Contact:

Re: Different random after scroll back

#2 Post by briarbun » Tue Feb 25, 2020 12:29 pm

Is there a way to roll this number upon the start of the game and then store it until needed, instead of rolling when it is needed? That way the player would scroll back in the dialogue (which is what I assume you mean, I'm not great at code) and still have the same number presented, because they would have to start a new game to get a new number.

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

Re: Different random after scroll back

#3 Post by rames44 » Tue Feb 25, 2020 1:08 pm

The Ren’py random system is specifically designed to be repeatable in that manner. What you could do would be to use the underlying Python random library directly, rather than the Ren’py version.

This thread viewtopic.php?f=8&t=56439 has an example of a class that does this.

User avatar
RicharDann
Regular
Posts: 179
Joined: Thu Aug 31, 2017 11:47 am
Projects: Project New Legacy
Contact:

Re: Different random after scroll back

#4 Post by RicharDann » Tue Feb 25, 2020 1:13 pm

It's because you're using renpy.random, wich is made to support rollback. You can just use plain random module:

Code: Select all

    "Roulette spining"
    
    python:
        
        import random

        rlt_drop = random.randint(0, 37)

    "It's a [rlt_drop]"

User avatar
Alex
Lemma-Class Veteran
Posts: 2472
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Different random after scroll back

#5 Post by Alex » Tue Feb 25, 2020 1:53 pm

By the way, you can't stop players from er... kind of cheating. If your random number would be different after rollback, then player will be able to rollback until (s)he wins. And if you'll block the rollback function, player could save game before making stake and restore the game in case of lose...))

User avatar
RicharDann
Regular
Posts: 179
Joined: Thu Aug 31, 2017 11:47 am
Projects: Project New Legacy
Contact:

Re: Different random after scroll back

#6 Post by RicharDann » Tue Feb 25, 2020 2:45 pm

Alex makes a very good point. Another option could be to disable rollback, saving and loading, but ONLY during roulette or random element sections, and re-enable them once the casino label or screen is exited. If you do this make sure to warn the players beforehand so they know exactly how it works.

The player still could save before entering the casino, but at least it would be 'less' cheap and it would require more effort (shutting down or exiting the casino label, then reloading previous save, etc.)
Last edited by RicharDann on Tue Feb 25, 2020 3:17 pm, edited 1 time in total.

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

Re: Different random after scroll back

#7 Post by Imperf3kt » Tue Feb 25, 2020 4:44 pm

You're looking at this the wrong way.
How does knowing the roll affect gameplay?
Can you restructure the order of events to avoid any problems?

You could also block roll back at that exact moment
https://www.renpy.org/doc/html/save_loa ... k_rollback

I make use of this in a blackjack game I'm working on, it works a charm, roll back is only blocked for one click.

I also use renpy. retain_after_load to prevent save/load situations.
https://www.renpy.org/doc/html/save_loa ... after-load
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

hapciupalit
Newbie
Posts: 20
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: Different random after scroll back

#8 Post by hapciupalit » Wed Feb 26, 2020 5:41 am

Alex wrote:
Tue Feb 25, 2020 1:53 pm
By the way, you can't stop players from er... kind of cheating. If your random number would be different after rollback, then player will be able to rollback until (s)he wins. And if you'll block the rollback function, player could save game before making stake and restore the game in case of lose...))
Shit. I didn't think this through. You're right. This roulette is just going to ruin my money system.

hapciupalit
Newbie
Posts: 20
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: Different random after scroll back

#9 Post by hapciupalit » Wed Feb 26, 2020 5:43 am

RicharDann wrote:
Tue Feb 25, 2020 2:45 pm
Alex makes a very good point. Another option could be to disable rollback, saving and loading, but ONLY during roulette or random element sections, and re-enable them once the casino label or screen is exited. If you do this make sure to warn the players beforehand so they know exactly how it works.

The player still could save before entering the casino, but at least it would be 'less' cheap and it would require more effort (shutting down or exiting the casino label, then reloading previous save, etc.)
Yeah, but still this will ruin the gameplay and the other ways of making money would be pointless. I need to find a way to rig the roulette. Or maybe put a limit of money you can win.

How do I disable save/load?

User avatar
RicharDann
Regular
Posts: 179
Joined: Thu Aug 31, 2017 11:47 am
Projects: Project New Legacy
Contact:

Re: Different random after scroll back

#10 Post by RicharDann » Wed Feb 26, 2020 11:53 am

As I now think about it more carefully, disabling the ability to save and load the game is not a very user-friendly thing to do.

It is technically possible to make the save and load buttons insensitive (unclickable) with some boolean variables for example, but many will find it annoying.

A clever player will always find ways to cheat, and fighting against Ren'Py's handy features is probably not a good idea. Most likely it's better to try and restrict rollback when necessary using the functions found in the page Imperf3kt mentioned.

hapciupalit
Newbie
Posts: 20
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: Different random after scroll back

#11 Post by hapciupalit » Thu Feb 27, 2020 2:29 am

RicharDann wrote:
Wed Feb 26, 2020 11:53 am
As I now think about it more carefully, disabling the ability to save and load the game is not a very user-friendly thing to do.

It is technically possible to make the save and load buttons insensitive (unclickable) with some boolean variables for example, but many will find it annoying.

A clever player will always find ways to cheat, and fighting against Ren'Py's handy features is probably not a good idea. Most likely it's better to try and restrict rollback when necessary using the functions found in the page Imperf3kt mentioned.
Well in that case I guess the best solution would be to limit the amount of earnings you can win at roulette. Thank you for your help.

strayerror
Regular
Posts: 111
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Different random after scroll back

#12 Post by strayerror » Sat Feb 29, 2020 11:03 am

Assuming the "cheat" is changing a decision made prior to the random call, another option (depending on how linear the game is) could be to go back to RenPy's rollback-compatible random and combine it with fixed rollback[1], which would allow rollback but not changing the decision/bet already made. If the game is sufficiently linear this may be a solution, however if your game is more open a savvy player could likely still route around it.

[1]: https://www.renpy.org/doc/html/save_loa ... x_rollback

hapciupalit
Newbie
Posts: 20
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: Different random after scroll back

#13 Post by hapciupalit » Sun Mar 01, 2020 4:41 am

strayerror wrote:
Sat Feb 29, 2020 11:03 am
Assuming the "cheat" is changing a decision made prior to the random call, another option (depending on how linear the game is) could be to go back to RenPy's rollback-compatible random and combine it with fixed rollback[1], which would allow rollback but not changing the decision/bet already made. If the game is sufficiently linear this may be a solution, however if your game is more open a savvy player could likely still route around it.

[1]: https://www.renpy.org/doc/html/save_loa ... x_rollback
Thanks for your replay. The game is not linear at all. It’s a sandbox game with different timelines.

Post Reply

Who is online

Users browsing this forum: Google [Bot]