Ren'Py Problem with money verification for in-game purchase.

zenergyblack

Newbie
Mar 29, 2022
30
3
I have declared the variable as default "stardust = 0" in the script.rpy.
1690307649325.png
My problem is with the screens; I don't quite understand their functioning. I am checking if the stardust is >= 1 to be able to make a purchase, but even though it checks correctly and tells me that I don't have enough stardust, it still lets me continue buying. I am attaching the code.

1690308174774.png
Basically, when I press the "test.png" button in-game, it takes me to a screen that displays the amount of stardust and buttons to go back or make a purchase. The problem is that the stardust amount doesn't update after the purchase unless I leave that screen. It also keeps allowing me to buy when I have zero stardust, and both messages pop up, one saying I obtained an item and the other saying I don't have enough money.

The system is a gachapon, and I am trying to do it this way, but I am encountering this problem. Thank you for the help.
 

zenergyblack

Newbie
Mar 29, 2022
30
3
You prob need to call the screen again after the variable is updated if it indeed updates correctly.
You should call it on a button in "gachaResultado" to go back to the previous screen, but how can it be done? Is there any kind of "action Jump Screen" or something similar?
I'm using a "showmenu" for the back button, but it doesn't seem to be working.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
My problem is with the screens;
No, your problem is the screens, and the fact that you try to do something without having read the documentation (available in your computer, in the same directory than Ren'Py).


A shop system should looks like that:
Python:
screen shop():
    hbox:
        imagebutton:
            auto "whatever_%s.png"
            action If( store.stardust >= 1, [ SetVariable( "product", store.product +1 ), SetVariable( "stardust", store.stardust - 1) ] ), function( renpy.notify, "You don't have enough stardust" ) )
        imagebutton:
            auto "whatever_else_%s.png"
            action If( store.stardust >= 1, [ SetVariable( "product1", store.product1 +1 ), SetVariable( "stardust", store.stardust - 1) ] ), function( renpy.notify, "You don't have enough stardust" ) )
And it's all...

Of course, it can be extended, but there's really no need for more, and especially no need for your "gachaResultado" screen that totally broke your game.

If really you need complex computation, then you should quit the screen, at least to make the purchase effective immediately.
Python:
label purchase:
    while True:
        call screen shop
        if _return == "whatever":
            if stardust >= 1:
                $ product += 1
                $ stardust -= 1
            else:
                $ renpy.notify( "You don't have enough stardust" )
        elif _return == "whatever else":
            [...]
        elif _return == "quit":
            return
   
label whatever:
    menu:
        "enter the shop ?"
        "yes":
            call purchase
        "no":
            [...]

screen shop():
    vbox:
        imagebutton:
            auto "whatever_%s.png"
            action Return( "whatever" )
        imagebutton:
            auto "whatever_else_%s.png"
            action Return( "whatever else" )
        imagebutton:
            auto "quit_%s.png"
            action Return( "quit" )
 
  • Like
Reactions: osanaiko

zenergyblack

Newbie
Mar 29, 2022
30
3
No, your problem is the screens, and the fact that you try to do something without having read the documentation (available in your computer, in the same directory than Ren'Py).


A shop system should looks like that:
Python:
screen shop():
    hbox:
        imagebutton:
            auto "whatever_%s.png"
            action If( store.stardust >= 1, [ SetVariable( "product", store.product +1 ), SetVariable( "stardust", store.stardust - 1) ] ), function( renpy.notify, "You don't have enough stardust" ) )
        imagebutton:
            auto "whatever_else_%s.png"
            action If( store.stardust >= 1, [ SetVariable( "product1", store.product1 +1 ), SetVariable( "stardust", store.stardust - 1) ] ), function( renpy.notify, "You don't have enough stardust" ) )
And it's all...

Of course, it can be extended, but there's really no need for more, and especially no need for your "gachaResultado" screen that totally broke your game.

If really you need complex computation, then you should quit the screen, at least to make the purchase effective immediately.
Python:
label purchase:
    while True:
        call screen shop
        if _return == "whatever":
            if stardust >= 1:
                $ product += 1
                $ stardust -= 1
            else:
                $ renpy.notify( "You don't have enough stardust" )
        elif _return == "whatever else":
            [...]
        elif _return == "quit":
            return
  
label whatever:
    menu:
        "enter the shop ?"
        "yes":
            call purchase
        "no":
            [...]

screen shop():
    vbox:
        imagebutton:
            auto "whatever_%s.png"
            action Return( "whatever" )
        imagebutton:
            auto "whatever_else_%s.png"
            action Return( "whatever else" )
        imagebutton:
            auto "quit_%s.png"
            action Return( "quit" )
You're welcome! I've managed to apply what you've said. It's important to clarify that it's not a shop, but rather a gacha game, although it might be similar. The thing is, I have one more question. In the future, I'm planning to make an animation appear when you get a certain item in the gacha. Right now, I'm using the screen to display the result frame, but I want it to disappear after a few seconds. I think it's not possible to use renpy.pause on the gachaResultado screen. Is there any way to achieve this?
1690332135387.png
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
Right now, I'm using the screen to display the result frame, but I want it to disappear after a few seconds.
Well, would you've read the documentation that you would have learned about the screen action...