Ren'Py RenPy-Imagebutton

VeritasLex

Newbie
Feb 6, 2020
50
3
Hello.
I am in the process of programming a game and in the game there should be the possibility to search images via image button.
But unfortunately it does not work as I would like it to.

Problem:
If you click on the image, the image is displayed, but the text starts again from the beginning, if you have already read the text a little bit.

Question:
Can someone explain to me as easily as possible how to get the whole thing to display the image and have the text continue right there?

PS:
My English is very bad, so I take a translator.
I apologize now already if the translation is not quite understandable.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
Using show screen and hide screen is almost always the wrong answer.

Use call screen instead.

show screen adds a screen to the UI and immediately continues (which is why the hide screen is needed).
call screen adds a screen to the UI and waits for the player to interact with it. The screen is automatically closed when the player triggers an action().

It has become a common mistake recently, I do not know why.

The other recent common mistake (just in case) is developers creating a screen for each imagebutton. Do not do it. A single screen should (usually) contain all the buttons and clickables a player can interact with at that time. It is better to code if statements within the screen than to use show screen and hide screen. I have no idea where people picked up that bad habit.

show screen can be useful. But normally, it is best used for showing things like toolbars or statusbars.

Edit: For other people, the code is this:

You don't have permission to view the spoiler content. Log in or register now.
 
Last edited:

VeritasLex

Newbie
Feb 6, 2020
50
3
Using show screen and hide screen is almost always the wrong answer.

Use call screen instead.

show screen adds a screen to the UI and immediately continues (which is why the hide screen is needed).
call screen adds a screen to the UI and waits for the player to interact with it. The screen is automatically closed when the player triggers an action().

It has become a common mistake recently, I do not know why.

The other recent common mistake (just in case) is developers creating a screen for each imagebutton. Do not do it. A single screen should (usually) contain all the buttons and clickables a player can interact with at that time. It is better to code if statements within the screen than to use show screen and hide screen. I have no idea where people picked up that bad habit.

show screen can be useful. But normally, it is best used for showing things like toolbars or statusbars.
Could you send me an example of what it should look like?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,285
Using show screen and hide screen is almost always the wrong answer.

Use call screen instead.
Yes... but also no ???

There's something I don't get in the question, even taking in count the translation issue: The code do not works as it is described by the text.

I tried his code with a 7.4.5 and a 8.0. As expected, clicking on the imagebutton do not affect the game flow. It show the image, but since the screen is shown, it works independently to the game flow, and especially do not return to it.

There's something missing in the demonstration code he shown. And I guess it's in this something that lie the problem.

Plus, call screen is blocking, while the second hide screen sogehts in the code demonstration make me guess that the screen is expected to stay for few interactions. Some kind of X-Ray version, or alternate angle, for the current image.


From my point of view, the answer is :
Python:
label whatever:
    "abcd"

    show screen sogehts( "image name" )

    "blibli"
    "blabla"
    "blublu"
    
    # Hide if never used
    hide screen sogehts

    "END"
    return

screen sogehts( imgName ):

    # By default, shown the button
    default shown = False

    # If the button have been clicked
    if shown:
        # Show the image
        add imgName xalign 0.5 yalign 0.5

    # Else
    else:
        # Show the button.
        imagebutton:
            # Better than /idle/ + /hover/  
            auto "button_%s"
            # Mark that the button have been clicked
            action SetScreenVariable( "shown", True )
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,581
2,219
My advice earlier was just general advice.
Your buttons are behaving like a mini-toolbar - so my advice was not relevant to your question.

Looking at your code now...

Like Anne, I am not sure what the problem is. I have copy/pasted your code and run it and I do not see any repeated text (starts again from the beginning), even if I set text speed below 100%.

The buttons and the shown image are both hidden by the hide screen sogehts and hide screen geschafft1. If anything, the second hide screen sogehts is not needed.

I am also unsure what you are trying to do. It almost sounds like a gallery, where clicking on a thumbnail/button shows a full screen image. (Gallery example #1, ).

It is not clear to me if the image you are adding (as part of geschafft1) is a full screen image which overrides the scene picture or something smaller (maybe a character picture in the corner of the screen or something).

I know translation can be a pain, but like Anne... I think your example is somehow different from the code you are running.

The code I used to test:

You don't have permission to view the spoiler content. Log in or register now.

I think we are still missing some critical part of the puzzle.
 
Last edited: