Ren'Py [SOLVED] Trying to create a mini game script in a linear VN that will return the player to a different part of the story each time they play

Heisenberg867

Newbie
Jul 18, 2018
90
149
The basic idea is that the player is playing the same game for larger stakes every time. I've got most of it working perfectly: before each iteration, a different variable in the main script is set to "true" that affects the difficulty and stakes present in the game script via a series of 'if' statements in the game script.

The tricky part is that when the player hits the "exit" button inside the game, I want that button to send them to a different label in the main script depending on which variable is set to "true". In this case, the current variables I'm using are market0 and market1. Below is the "Play Again?" screen inside the game. You can see my initial attempt to modify the "Quit" action button with a pair of "if" statements that affect the Jump function, but Ren'Py doesn't like it one bit. The error it throws is "expected a keyword argument or end of line".

Any ideas, oh wise F95 gurus?

P.S. As a last resort, I'm willing to kludge by creating a new mini game script for every instance the game is used, but that strikes me as extremely inelegant.

Code:
screen market_again_screen:
    modal True
    key "hide_windows" action NullAction()
    $ renpy.block_rollback()

    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayAgainNormal.png")
        hover Transform("images/Market/PlayAgainHover.png")
        action [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("market_label"),]
        unhovered Hide("displayTextScreen")
    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayExitNormal.png")
        hover Transform("images/Market/PlayExitHover.png")
        action:
            if market0 == True
                [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("finishup"),]
            if market1 == True
                [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("whoa"),]
        unhovered Hide("displayTextScreen")
EDIT: I figured it out. The 'if' statement needs to create a whole new image button, like so:

Code:
screen market_again_screen:
    modal True
    key "hide_windows" action NullAction()
    $ renpy.block_rollback()

    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayAgainNormal.png")
        hover Transform("images/Market/PlayAgainHover.png")
        action [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("market_label"),]
        unhovered Hide("displayTextScreen")

    if market_0 == True:

        imagebutton:
            xpos 0
            ypos 0
            focus_mask True
            idle Transform("images/Market/PlayExitNormal.png")
            hover Transform("images/Market/PlayExitHover.png")
            action [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("finishup"),]
            unhovered Hide("displayTextScreen")

    if market_1 == True:

        imagebutton:
            xpos 0
            ypos 0
            focus_mask True
            idle Transform("images/Market/PlayExitNormal.png")
            hover Transform("images/Market/PlayExitHover.png")
            action [Hide("displayTextScreen"), Hide("market_again_screen"),Hide("market_scr"),Hide("screen_market_losemoney"),Hide("screen_market_wonmoney"), Jump("whoa"),]
            unhovered Hide("displayTextScreen")
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,226
EDIT: I figured it out. The 'if' statement needs to create a whole new image button, like so:
Not necessarily. The problem was that you can't use if like you did, as direct argument for a property. But you can use it to redefine the property itself :
Code:
screen market_again_screen:
    [...]

    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayExitNormal.png")
        hover Transform("images/Market/PlayExitHover.png")
        if market_0 == True:
            action [Hide("displayTextScreen"), [...] ]
        elif market_1 == True:
            action [Hide("displayTextScreen"), [...] ]
        else:
            action NullAction()
        unhovered Hide("displayTextScreen")

This said, if the test was is market_0 is True or not, you could have either used the screen action:
Code:
screen market_again_screen:
    [...]

    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayExitNormal.png")
        hover Transform("images/Market/PlayExitHover.png")
        action If( market_0 is True, [ Hide("displayTextScreen"), [...] ], [Hide("displayTextScreen"), [...] ] )
        unhovered Hide("displayTextScreen")
Or by using the inline if structure :
Python:
screen market_again_screen:
    [...]

    imagebutton:
        xpos 0
        ypos 0
        focus_mask True
        idle Transform("images/Market/PlayExitNormal.png")
        hover Transform("images/Market/PlayExitHover.png")
        # Will use what is BEFORE the /if/ if the condition is
        # True, else what is AFTER it.
        action [ Hide("displayTextScreen"), [...] ] if market_0 is True else [Hide("displayTextScreen"), [...] ]
        unhovered Hide("displayTextScreen")