Ren'Py Need help calling a mini game with variables

bdaywans

Newbie
Apr 15, 2017
35
22
I'm using a match-3 minigame as a key component to my renpy game and I've gotten it to work in the 2 generic instances I need it to so far but since I'm new to renpy and making games in general I'm not sure how to go about this next part...

The idea is that the mc will compete against a number of different npcs and it seems pointless to repeat the game code for every round or every character so I figure there has to be a way that I can call the game when necessary and then set certain variables, or when I want to call a label mid game that may change per character per game how do I get back to the game? But since I don't know renpy I don't know what to look up to find how to do it.

Here is the game code I'm using:
Python:
label Game:
    $ GameCount += 1


screen memo_scr:

    ##### Timer
    timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memo_game_lose") ) repeat True

    text str(memo_timer) xalign 0.5 yalign 0.0
    text str(loss) xalign 0.25 yalign 0.0
    text str(win) xalign 0.75 yalign 0.0
    grid 3 5 xalign 0.5 yalign 0.23:
        for card in cards_list:
            button:
                background None
                if card["c_chosen"]:
                    add card["c_value"]
                else:
                    add "C"

                action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )




init:
    python:
        def cards_shuffle(x):
            renpy.random.shuffle(x)
            return x

    ##### Images
    image A = "img_1.png"
    image B = "img_2.png"
    image D = "img_3.png"

    image C = "back.png"



    default gameSet = 0
    default gameMCWin = 0
    default powerplay = False
    $ gameSet = 0
    $ gameMCWin = 0

label memoria_game:
    scene black
    default win = 0
    default loss = 0
    default winImg = 1
    default lossImg = 1
    default powerdom = "x"
    default competitor = "npc1"
    image img_competition = "wall-[competitor]-[winImg]-[powerdom].png"
    image img_mc = "wall-mc1-[lossImg].png"
    show img_competition at left
    show img_mc at right

    $ values_list = ["A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "D", "D", "D"]

    $ values_list = cards_shuffle(values_list)

    $ cards_list = []
    python:
        for i in range (0, len(values_list) ):
            cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )

    $ memo_timer = 25.0

    show screen memo_scr

    label memo_game_loop:
        $ can_click = True
        $ turned_cards_numbers = []
        $ turned_cards_values = []

        $ turns_left = 3

        label turns_loop:
            if turns_left > 0:
                $ result = ui.interact()
                $ memo_timer = memo_timer
                $ turned_cards_numbers.append (cards_list[result]["c_number"])
                $ turned_cards_values.append (cards_list[result]["c_value"])
                $ turns_left -= 1
                jump turns_loop

        $ can_click = False

        if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
            $ renpy.pause (0.5, hard = True)
            python:
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_chosen"] = False
        else:
            $ renpy.pause (0.5, hard = True)
            python:
            
                for i in range (0, len(turned_cards_numbers) ):
                    cards_list[turned_cards_numbers[i]]["c_value"] = Null()


                for j in cards_list:
                    if j["c_chosen"] == False:
                        renpy.jump ("memo_game_loop")
                renpy.jump ("memo_game_win")



        jump memo_game_loop

label memo_game_lose:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You lose!"
    $ gameSet += 1
    $ loss += 1
    $ lossImg += 1
    if loss >= 4:
        $ loss == 3
    if lossImg >= 4:
        $ lossImg = 3
    if loss == 2:
        if GameCount <= 1:
            $ lossImg = 2
            jump mulligan
        elif GameCount >= 2:
            jump memoria_game
    if gameSet <= 4:
        if loss == 3:
            jump matchEnd_loss
        elif loss <= 2:
            jump memoria_game
    elif gameSet == 5:
        if $ loss == 3:
            jump matchEnd_loss
        elif loss <= 2:
            jump matchEnd_win

label memo_game_win:
    hide screen memo_scr
    $ renpy.pause (0.1, hard = True)
    $ renpy.pause (0.1, hard = True)
    "You win!"
    $ gameSet += 1
    $ win += 1
    $ winImg += 1
    if win >= 4:
        $ win == 3
    if winImg >= 5:
        $ winImg = 4
    if gameSet == 2:
        if win == 2:
           # jump to specific cut scene
           "There is dialogue that will go here"
        
            #I want to be able to call the menu below without it having to live WITHIN the game code itself
            label options-menu:
                menu:
                    "Select Option":
                        menu:
                            "option1":
                                $ variable
                            "option2":
                                $ variable
                            "..."
                        $ memo_timer += 2.0
                        $ option = True
                        $ winImg += 1
                    "No":
                        jump memoria_game
    if gameSet <= 4:
        if win == 3:
            jump matchEnd_win
        elif win <= 2:
            jump memoria_game
    elif gameSet == 5:
        if win == 3:
            jump matchEnd_win
        elif loss <= 2:
            jump matchEnd_loss
What I'm trying to figure out is 3 things...

First after specific rounds I want t b able to call a label which will have some dialogue and images but then as soon as its over it returns to the game. But can I do that without resetting the game?
Code:
   if gameSet == 2:
        if win == 2:
           # jump to specific cut scene
           "There is dialogue that will go here"
          # jump back to this point in the game
...
Second, just like the above issue, I want to be able to call various menus based on the game... depending on who you challenge you may have different options so rather then making 3 or 4 menus live inside the game it seemed like it'd make more sense to have it call them as needed. But again, if I do that and then tell it to return will it reset or break the minigame?

Code:
   if gameSet == 2:
        if win == 2:

            label options-menu:
                menu:
                    "Select Option":
                        menu:
                            "option1":
                                $ variable
                            "option2":
                                $ variable
                            "..."
                        $ memo_timer += 2.0
                        $ option = True
                        $ winImg += 1
                    "No":
                        jump memoria_game
Lastly and this really should be easy but I don't see why its not working. Certain options will also add or subtract to the time limit. In this case it startes at 25s and if an option is select from the menu it is supposed to add 2s but it doesn't.

Code:
                        $ memo_timer += 2.0
I think the last part would be the ending options that will change based on the above (who was playing, what the stats were, etc) but I'm assuming I could just control that with something like:
Code:
jump matchEnd_win[npc]
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,190
but since I'm new to renpy and making games in general I'm not sure how to go about this next part...
I don't want to be arsh, but perhaps that before trying to integrate a mini-game in your own game, you should take some time to learn the basis of Ren'py ; or at least read the first page of the help provided with the SDK.
No one sit on the driver seat of a Formula One/Indy car (depend of your preference) thinking that having look at how others race is enough knowledge, nor after having just looked at a "how-to drive" tutorial on the net. And it's the same for Ren'py. Looking what other do and tutorials is good, but you also need to practice a lot and learn the basis before trying to go big.


First after specific rounds I want t b able to call a label which will have some dialogue and images but then as soon as its over it returns to the game.
The answer is inside the question. You want to the label, then just do it. And you'll have to simply from the called label when what you've to do inside will be done.

Code:
label whatever:
    [...]
    call myCalledLabel
    [...]

label myCalledLabel:
    [...]
    return

But can I do that without resetting the game?
official documentation said:
The call statement is used to transfer control to the given label. It also pushes the next statement onto the call stack, allowing the return statement to return control to the statement following the call.

Second, just like the above issue, I want to be able to call various menus based on the game...
Same answer than above. Except that this time you put a menu inside the called label.
Code:
label whatever:
    [...]
    call myCalledMenu
    [...]

label myCalledMenu:
    menu:
        "choice 1":
            [...]
        "choice 2":
            [...]
    [...]
    return
Special note: The statement can take a label name, but it's still an undocumented feature.
Code:
label whatever:
    [...]
    call myCalledMenu
    [...]

menu myCalledMenu:
    "choice 1":
        [...]
        return
    "choice 2":
        [...]
        return

depending on who you challenge you may have different options so rather then making 3 or 4 menus live inside the game it seemed like it'd make more sense to have it call them as needed.
Or you can use conditional choice (still in the menu help page linked above) :
Code:
menu myCalledMenu:
    "choice when player challenge 'this guy'" if challenger = "this guy":
        [...]
        return
    "choice when player challenge either 'this guy', 'that girl' or 'the champ'" if challenger in [ "this guy", "that girl", "the champ" ]:
        [...]
        return
    "choice when player challenge everyone":
        [...]
        return
    "choice when player challenge everyone except 'the champ'" if not challenger == "the champ":
        [...]
        return

In this case it startes at 25s and if an option is select from the menu it is supposed to add 2s but it doesn't.

Code:
                        $ memo_timer += 2.0
Well, it should. There's surely a problem somewhere in the code that prevent it to effectively works... but honestly I'll not start to debug you used for your game ; 62 versions of Ren'py have been released since the code you use have been wrote. There's too many things that still works but are really old fashioned and shouldn't be done like this anymore. The two most obvious being the text str(memo_timer) in place of the now traditional , and the $ result = ui.interact() in place of .
 
  • Like
Reactions: bdaywans

bdaywans

Newbie
Apr 15, 2017
35
22
Thanks anne O'nymous and honestly I appreciate the straightforward feedback. This is all new to me and while I don't intend to take on more then I can do a lot of it has been trial and error and looking things up but I will revisit the SDK as cleary I either didn't read it or I didn't find it... so I try to bother other people in forums only when my attempts to figure it out on my own fail. But to your latter point if I'm working with archaic code that probably isn't helping me resolve those issues. Beyond trying to incorporate this minigame the rest of the game is generic, straightforward vn but thanks for the links and anything I can do to clean up/update my code I'll certainly do.
 
  • Like
Reactions: anne O'nymous