Page 1 of 1

Different random after scroll back

Posted: Tue Feb 25, 2020 9:41 am
by hapciupalit
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
    

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 12:29 pm
by briarbun
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.

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 1:08 pm
by rames44
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.

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 1:13 pm
by RicharDann
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]"

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 1:53 pm
by Alex
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...))

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 2:45 pm
by RicharDann
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.)

Re: Different random after scroll back

Posted: Tue Feb 25, 2020 4:44 pm
by Imperf3kt
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

Re: Different random after scroll back

Posted: Wed Feb 26, 2020 5:41 am
by hapciupalit
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.

Re: Different random after scroll back

Posted: Wed Feb 26, 2020 5:43 am
by hapciupalit
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?

Re: Different random after scroll back

Posted: Wed Feb 26, 2020 11:53 am
by RicharDann
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.

Re: Different random after scroll back

Posted: Thu Feb 27, 2020 2:29 am
by hapciupalit
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.

Re: Different random after scroll back

Posted: Sat Feb 29, 2020 11:03 am
by strayerror
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

Re: Different random after scroll back

Posted: Sun Mar 01, 2020 4:41 am
by hapciupalit
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.