CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py How to check if imagebutton is pushed[SOLVED]

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Yeah, you guys are probably ready to jump to "Hey, you can just use "Clicked" or something", but actually let me explain.
Basic tutorial point in-game.
So, I've got a screen with a button to appear on top corner of the screen.
At that point MC says something like "to get to see %stats_screen% you need to push this button"
Then, once the button is pushed, a new screen appears and MC should say "to see %char_x _stats_screen% you need to push this button at the bottom of this screen"
So, the question is, how to make the check, since I want MC and the textbox where he says tutorial stuff to appear only once
 

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
I guess, it's pretty obvious that it's
if ... =True, but how to make a specific variable that should be set to True if that button was pushed?
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,259
I think you're possibly trying to solve the wrong problem.

But first, to answer the question you've asked...

Usually, a clickable button has an .
That will usually look something like:

Python:
    imagebutton:
        auto "images/myclickablebutton_%s.jpg"
        focus_mask True
        action Jump("myspeciallabel")

In this case, jumping to the label myspeciallabel:.

But, you can give it a list of actions, within reason.
That "within reason" is pretty much that some actions are one way. Since what they do could be considered a "final action", any other action listed after them won't be executed. You can't Jump to a label for example, and then do something else. Basically there are actions which end the screen, and other that stay within the screen. You'll learn which is which as you go.

The answer to your asked question is probably something like:

Python:
    imagebutton:
        auto "images/myclickablebutton_%s.png"
        focus_mask True
        action [ SetVariable("myvar1", True), Show("myotherscreen") ]

Where the square brackets denote a list of things. In this case, a list of actions, with each action separated by a comma.

I mean, you could just jump to a label; then within that label set the variable using $ myvar1 = True, followed by call screen myotherscreen(). Either should be fine.

However, I suspect what you really want is to make sure that when you click the button to show the stats screen - that you can only interact with the stats screen and nothing else.

For that, you want .
It's a parameter of a screen itself. It basically says that until the user does something to closes the screen (usually via an action), only this screen can be interacted with. No variables required. In this case, I think you probably want modal True on your stats screen.
 

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Maybe I'm just explaining things like an idiot.
Modal True/False is stuff that's done to some screens already.

So, I will try to explain with screens and stuff.
Image 001 - MC says the quote about some kind of stuff. 001.png
Image 002 - MC says that to watch it, he needs to push the button in top right corner of the screen. The button has appeared as the screen was showed with show screen screen1 002.png
Now, what I want to happen is for the game to freeze unless the player pushes this specific button. AT first I've thought "Let's just create the separate screen which will be set to Modal = True"(I want the screen with this button to be Modal/Freeze everything else only this one time, during tutorial phase) and ask for it to be showed, but... I'll try my best to explain further.

Once MC pushes this button, another screen appears, since it's written in imagebutton Action stuff.
The code is basic:
modal False/True #If Player is in Tutorial - it's Screen with True, if not - different Screen with False
imagebutton:
xalign 0.98
yalign 0.02
idle "gui/Screen1/Screen1Idle.png"
hover "gui/Screen1/Screen1Hover.png"
action Show ("screen2")

What do I want to happen next is:
Player gets to Screen2 - 003 in here and then gets another dozen of instructions where he's being asked to push on a specific profile. 003.png
Once it's done - player gets tranferred to another screen where gets a last part of the tutorial with text on top of the screen - 004. 004.png
And then, once everything's finished,the game should continue)
Any help?
Thanks in advance.
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,577
4,699
Asking as the Devil's Advocate:

Why do you think you need a tutorial?

Gamers have played dozens to hundreds of games that all have icons for "phone" or "quest" or "inventory". We already KNOW that we'll need to use at least some of the UI buttons to get anywhere. Everyone is capable of exploring the UI and understanding the basics, that is, unless you've invented some entirely new paradigm of adult gaming.

You could save yourself all the trouble and instead concentrate on the stuff that's important - gameplay, dialogue, artwork.
 
  • Like
Reactions: ScrewMe

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Asking as the Devil's Advocate:

Why do you think you need a tutorial?

Gamers have played dozens to hundreds of games that all have icons for "phone" or "quest" or "inventory". We already KNOW that we'll need to use at least some of the UI buttons to get anywhere. Everyone is capable of exploring the UI and understanding the basics, that is, unless you've invented some entirely new paradigm of adult gaming.

You could save yourself all the trouble and instead concentrate on the stuff that's important - gameplay, dialogue, artwork.
Well, the main reasoning is that in my VN, for example, Char X Lovepoints won't be shown to player as "Hearts" or soemthing like it - it will be "Char X has visited your page %number% times".
In this case, if I tell the player "Oh, and also you can see how this much this girl likes you by seeing it in this area in there" and people will have to spend extra time to find that instead of simply "Oh, that's here".

Plus, it's just the stuff that I want to learn how to do, if possible - like, if I'll decide to make some kind of Ren-Py based RPG few years later down the line.

UPD: Seem to be figuring way out: creating separate screens for each action and adding text in there, but it looks meh. Dunno what to do now.
 
  • Like
Reactions: osanaiko

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Asking as the Devil's Advocate:

Why do you think you need a tutorial?

Gamers have played dozens to hundreds of games that all have icons for "phone" or "quest" or "inventory". We already KNOW that we'll need to use at least some of the UI buttons to get anywhere. Everyone is capable of exploring the UI and understanding the basics, that is, unless you've invented some entirely new paradigm of adult gaming.

You could save yourself all the trouble and instead concentrate on the stuff that's important - gameplay, dialogue, artwork.

Must say, you gave me an idea: instead of programming stuff and beating my head over keyboard, will simply use a few pictures that I've prerendered earlier and add pointers to paint to each time character says tutorial stuff.

Easy solution, but still...I tend to think that there is a solution which will make both the player more engaged and won't cause a headache for me. Or maybe I'm just explaining what I want to achieve like a moron:)
Thanks anyway:)
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,577
4,699
Must say, you gave me an idea: instead of programming stuff and beating my head over keyboard, will simply use a few pictures that I've prerendered earlier and add pointers to paint to each time character says tutorial stuff.

Easy solution, but still...I tend to think that there is a solution which will make both the player more engaged and won't cause a headache for me. Or maybe I'm just explaining what I want to achieve like a moron:)
Thanks anyway:)
Absolutely not a moron - I think we understood what you wanted, but the trouble is that what you thought was needed is just plain hard to achieve.

In Renpy it's easy enough to add some UI elements that do their thing, but it is not simple at all to have a "meta" layer that wraps and controls access to those elements.

I think the static images idea is a fine solution. It's the old 20%/80% rule in action yet again - the first 20% of effort gives you 80% of the benefits.
 

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Absolutely not a moron - I think we understood what you wanted, but the trouble is that what you thought was needed is just plain hard to achieve.

In Renpy it's easy enough to add some UI elements that do their thing, but it is not simple at all to have a "meta" layer that wraps and controls access to those elements.

I think the static images idea is a fine solution. It's the old 20%/80% rule in action yet again - the first 20% of effort gives you 80% of the benefits.
And speaking of why I think this stuff is important - my game will have QTEs, where characters will trashtalk each other in-between trading blows(if example's needed, BaDIKs fights are something like that).
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,527
8,062
Unless I've heavily misunderstood the question, this should be fairly simple to do:

Python:
label start:
    Player "To get to see Stat Screen you need to push this button..."
    call screen buttonexample
    Player "This line will show only after the player has pressed that button, which is now hidden."


screen buttonexample():
     textbutton "Stat Screen":
            xalign 0.5
            action [Hide("buttonexample"), Return()]
 

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Unless I've heavily misunderstood the question, this should be fairly simple to do:

Python:
label start:
    Player "To get to see Stat Screen you need to push this button..."
    call screen buttonexample
    Player "This line will show only after the player has pressed that button, which is now hidden."


screen buttonexample():
     textbutton "Stat Screen":
            xalign 0.5
            action [Hide("buttonexample"), Return()]
The issue is : the button that I have on screen already Shows another Screen.
It's smth like:
Player "Now there's a screen with red roses"
show screen rosesarered
Player "Once you see, that roses are red, if you push on red rose on top, screen with blue violets appear"

screen rosesarered:
imagebutton:
xalign 0.98
yalign 0.02
idle "rosesarered1.png"
hover "rosesarered2.png"
Action Show ("violetsareblue")


So, if I get your way out of this, is to simply use "call" instead of "show" with return as the action is done? I got it right?
 

Winterfire

Forum Fanatic
Respected User
Game Developer
Sep 27, 2018
5,527
8,062
The issue is : the button that I have on screen already Shows another Screen.
It's smth like:
Player "Now there's a screen with red roses"
show screen rosesarered
Player "Once you see, that roses are red, if you push on red rose on top, screen with blue violets appear"

screen rosesarered:
imagebutton:
xalign 0.98
yalign 0.02
idle "rosesarered1.png"
hover "rosesarered2.png"
Action Show ("violetsareblue")


So, if I get your way out of this, is to simply use "call" instead of "show" with return as the action is done? I got it right?
If you call a screen, the dialogue is interrupted until you return out of it.
You can return with a parameter too ( default is none), if needed.
So you could call another screen soon after returning.
 
  • Like
Reactions: ScrewMe

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,259
The issue is : the button that I have on screen already Shows another Screen.
[...]
show screen rosesarered

Generally speaking you use show screen if you want to add a custom screen to the current UI. It will sit there and can be interacted with, but the game continues regardless of whether it is used or not. (think taskbar or toolbar or stats summary).

call screen is more or less the same thing, except the game doesn't continue until the player interacts with the screen in a way that triggers an action.

Most new developers don't understand the difference and use show screen too often, when they really should be using call screen.

I mention all that because both have been mentioned and I want to make sure you don't fall into the trap.

Meanwhile, back to your original problem (which I'll admit, I'd missed the "tutorial" aspect of.)
It's RenPy, so there are lots of possible solutions. The ones mentioned already are all good.

But I'll add another one for you to consider.

Python:
default saw_rosesarered_tutorial = False

screen rosesarered():
    modal True
    textbutton "<CLICK ME>":
        xalign 0.9 yalign 0.2
        action Jump("playthru_continue")
    textbutton "<EXIT>":
        xalign 0.9 yalign 0.9
        action Jump("the_end")

    if saw_rosesarered_tutorial == False:
        text "This text will only appear the first time the screen is displayed (and subsequently closed)":
            xalign 0.1 yalign 0.8

    on "hide" action SetVariable("saw_rosesarered_tutorial", True)

    
label start:

    scene black with fade
    "*** START ***"


label repeat_rosesarered:

    call screen rosesarered

    "Should never reach here."


label playthru_continue:

    "You hit the button, well done."
    "Another line of text"
    jump repeat_rosesarered


label the_end:

    screen black with fade
    "*** THE END ***"
    return

This doesn't have the narrator or main character delivering dialogue, but instead has text which is shown as part of the screen only the first time the screen is displayed. After that, the variable is set to True and therefore the text isn't shown next time. That seems in keeping with the idea of a tutorial, and means the player can avoid clicking the button, but will see the "hint" or however you want to think about it, the first time they view that screen.

I could have removed the on "hide action SetVariable()" and instead used:
action [ SetVariable("saw_rosesarered_screen", True), Jump("playthru_continue") ]

But this is the thing about RenPy, there's always another way of doing something.
 
  • Like
Reactions: ScrewMe

ScrewMe

Active Member
Game Developer
Apr 11, 2018
564
1,523
Generally speaking you use show screen if you want to add a custom screen to the current UI. It will sit there and can be interacted with, but the game continues regardless of whether it is used or not. (think taskbar or toolbar or stats summary).

call screen is more or less the same thing, except the game doesn't continue until the player interacts with the screen in a way that triggers an action.

Most new developers don't understand the difference and use show screen too often, when they really should be using call screen.

I mention all that because both have been mentioned and I want to make sure you don't fall into the trap.

Meanwhile, back to your original problem (which I'll admit, I'd missed the "tutorial" aspect of.)
It's RenPy, so there are lots of possible solutions. The ones mentioned already are all good.

But I'll add another one for you to consider.

Python:
default saw_rosesarered_tutorial = False

screen rosesarered():
    modal True
    textbutton "<CLICK ME>":
        xalign 0.9 yalign 0.2
        action Jump("playthru_continue")
    textbutton "<EXIT>":
        xalign 0.9 yalign 0.9
        action Jump("the_end")

    if saw_rosesarered_tutorial == False:
        text "This text will only appear the first time the screen is displayed (and subsequently closed)":
            xalign 0.1 yalign 0.8

    on "hide" action SetVariable("saw_rosesarered_tutorial", True)

 
label start:

    scene black with fade
    "*** START ***"


label repeat_rosesarered:

    call screen rosesarered

    "Should never reach here."


label playthru_continue:

    "You hit the button, well done."
    "Another line of text"
    jump repeat_rosesarered


label the_end:

    screen black with fade
    "*** THE END ***"
    return

This doesn't have the narrator or main character delivering dialogue, but instead has text which is shown as part of the screen only the first time the screen is displayed. After that, the variable is set to True and therefore the text isn't shown next time. That seems in keeping with the idea of a tutorial, and means the player can avoid clicking the button, but will see the "hint" or however you want to think about it, the first time they view that screen.

I could have removed the on "hide action SetVariable()" and instead used:
action [ SetVariable("saw_rosesarered_screen", True), Jump("playthru_continue") ]

But this is the thing about RenPy, there's always another way of doing something.
My first idea was to create 2nd screen - so, basically when player gets it the 1st time - he sees the screen "rosesarered_tutorial" with text, but all the next times he would justbe showed standard "rosesarered" screen.Decided to scrap the idea in the end because getting a text on top of the screen with show text, trying to get the font, color and everything else to match the default one, then to manually find a way to position it on top AND to get the similar frame that the regular textbox is was just too much pain in the ass to do, since I want the protagonist to have his inner monologue: "Oh, they've added new button to site and now I can leave it in one click on top right corner of the screen" instead of "push button x to quit" by me. Breaks immersion a bit)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,007
16,293
You are all, except Osanaiko who was near, forgetting something... Ren'Py is procedural, not event based.

Therefore, it doesn't matters if there's a way to know when the button is pressed, because in the wanted context, there's no way to wait for it to be pressed before you continue :giggle:

This mean that Winterfire was the closest from a solution.

Python:
screen tutoButton1:

    imagebutton:
        auto "button1_%s.png"
        xpos 100 ypos 100
        action [ Show( "screenOpenedByButton1" ), Return() ]

screen tutoButton2:

    imagebutton:
        auto "button2_%s.png"
        xpos 100 ypos 100
        action [ Show( "screenOpenedByButton2" ), Return() ]

label tutorial:
    "To do this, press the button representing whatever"
    call screen tutoButton1
    pause 1.0
    hide screen screenOpenedByButton1 # assuming the screen is modal
    "Good."
    "Now, to do that, press the button representing that thing"
    call screen tutoButton2
    pause 1.0
    hide screen screenOpenedByButton2
    "Good."
Alternatively this should also works, while giving player more freedom:
Python:
screen tutoButton1:

    imagebutton:
        auto "button1_%s.png"
        xpos 100 ypos 100
        action [ Show( "screenOpenedByButton1" ), Function( renpy.notify, "Close the screen to continue" ), Return() ]

screen tutoButton2:

    imagebutton:
        auto "button2_%s.png"
        xpos 100 ypos 100
        action [ Show( "screenOpenedByButton2" ), Function( renpy.notify, "Close the screen to continue" ), Return() ]

label tutorial:
    "To do this, press the button representing whatever"
    call screen tutoButton1
    "Good."
    "Now, to do that, press the button representing that thing"
    call screen tutoButton2
    "Good."
 

AllNatural939

I am the bad guy?
Game Developer
Apr 3, 2024
309
324
I don't know if I understood correctly, but I see that maybe you are thinking too much without a real reason... Didn't you think of creating the same screen twice?... Let me explain.
You get to the point where your tutorial starts, the icon appears on the screen. Some text indicates that you must press this button in order to continue. The button is pressed and you jump to SCREEN 2 and do everything you want to do to explain things... The tutorial ends and you jump to the next step in the game, but this time the button (which is identical to the original) has the real function, without the tutorial in between, and therefore if you press it you go to SCREEN X, which is the one with all the real variables... Linear programming if it weren't for the minimum jumps. The game is impossible to continue if you don't press the button because the only way to continue the game is when you leave the tutorial.
Do you want everything to look exactly identical when you press the tutorial button and the real button? Just do the screen twice, but the tutorial one with other variables invented for the tutorial that you can manipulate as you wish. You don't need any check to see if the player has pressed the button and the game continues or not, because the real start of the game is marked by the end of the tutorial.