Ren'Py imagebutton perform function

Evildad

Member
Jan 7, 2019
113
218
Hy, me again.

I have a problem with my image button and the function that should be executed.
I'm really on the hose right now. As shown below, I have an image button within a label. When pressed, another label is to be called, the if statements are processed and then back to the previous screen where the image button was pressed. But i always end up in a previous label
Somehow I just don't get it baked to implement that. The only sad thing is that it worked before with a mormal menu and I just don't see my mistake.

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

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

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

Niv-Mizzet the Firemind

Active Member
Mar 15, 2020
571
1,111
Until someone more knowledgeable chimes in, why don't you use show screen game_navigation_arbeit instead of return in the label trinken_unterwegs, since so far it can only be called by that screen?

Also, I think that return gets you to a label, not a screen.
 

Evildad

Member
Jan 7, 2019
113
218
Until someone more knowledgeable chimes in, why don't you use show screen game_navigation_arbeit instead of return in the label trinken_unterwegs, since so far it can only be called by that screen?

Also, I think that return gets you to a label, not a screen.
it should be called from a total of 8 places. I only have it for testing until now. otherwise I wouldn't do the work ...
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
Python:
label Vor_dem_Haus:
    $ event_label = 0
    show screen menuebotten
    scene haus_v
  
    show screen game_navigation ############ starting point##############


    window hide
    $ renpy.pause(hard=True)
Boom.

This is absolutely not how you do a navigation screen.
Anything else than what follow is a broken trick that will stab you in the back one day or another:
Code:
label Vor_dem_Haus:
    $ event_label = 0
    show screen menuebotten
    scene haus_v
 
    call screen game_navigation
And that's all what is needed.


Python:
        if event_label == 0 or event_label == 1 or event_label == 10 or event_label == 11 or event_label == 12 or event_label == 13 or event_label == 14 or event_label == 15:
This could easily be simplified. Not only it would be a little faster (what here wouldn't change much) but also easier to read and maintain:
Code:
    if event_label in [ 0, 1, 10, 11, 12, ,13, 14, 15]:

Python:
label trinken_unterwegs: [B]# This should be edited and returned to the starting point[/B]
    if Nahrung <= 90:
        if Wasserspeicher >= 1:
            $ Wasser += 20
            A "Das war erfrischend."
            if Wasser >= 100:
                $ Wasser = 100
                return
            else:
                return
        else:
            A "Wir haben nicht mehr genügend Wasser! Wir sollten unser Wasservorrat auffüllen!"
            return
    else:
        A "Ich habe im momment kein durst."
        return
This is absolutely not a function. This is a called label that, once finished, will sent you back right after the line that shown the screen. And this is the reason why your code do not works.

I don't speak your native language, so can only guess what you wanted to do. But globally the valid code should looks more or less like that:
Code:
label Vor_dem_Haus:
    $ event_label = 0
    show screen menuebotten
    scene haus_v
    call screen game_navigation

label hinter_dem_Haus:
    $ event_label = 1
    show screen menuebotten
    scene haus_v
    call screen game_navigation


screen game_navigation():
    hbox:
        style "navi_style"
        xalign 0.5
        yalign 0.98

        if event_label in [ 0, 1, 10, 11, 12, 13, 14, 15]:
[...]

screen game_navigation_arbeit():
    hbox:
        xalign 0.5
        yalign 0.85

        if event_label == 0:
            hbox:
                imagebutton:
                    xalign 0.3
                    idle "navi_trinken"
                    hover "navi_trinken_hover"
                    action Jump("trinken_unterwegs")
[...]

label trinken_unterwegs: 
    if Nahrung <= 90:
        if Wasserspeicher >= 1:
            $ Wasser += 20
            A "Das war erfrischend."
            if Wasser >= 100:
                $ Wasser = 100
        else:
            A "Wir haben nicht mehr genügend Wasser! Wir sollten unser Wasservorrat auffüllen!"
    else:
        A "Ich habe im momment kein durst."
    call screen game_navigation_arbeit
 

Evildad

Member
Jan 7, 2019
113
218
ok, it seems to be very difficult for me to explain.

I have a label with this query ... (You have a drink there)
Code:
label trinken_unterwegs: [B]# This should be edited and returned to the starting point[/B]
    if Wasser <= 90:
        if Wasserspeicher >= 1:
            $ Wasser += 20
            A "Das war erfrischend."
            if Wasser >= 100:
                $ Wasser = 100
                return
            else:
                return
        else:
            A "Wir haben nicht mehr genügend Wasser! Wir sollten unser Wasservorrat auffüllen!"
            return
    else:
        A "Ich habe im momment kein durst."
        return
I want to go there from various other labels. Via the imagebutton. When "drink label" is through, I want to go back to the starting label.


an example...

Code:
label 1:
    $ event_label = 0
    show screen menuebotten
    scene haus_v
    call screen game_navigation # There is mine imagebutton


    window hide
    $ renpy.pause(hard=True)
   
label 2:
    $ event_label = 3
    show screen menuebotten
    scene haus_v
    call screen game_navigation # There is mine imagebutton
    #


    window hide
    $ renpy.pause(hard=True)
   
label 3:
    $ event_label = 3
    show screen menuebotten
    scene haus_v
    call screen game_navigation # There is mine imagebutton


    window hide
    $ renpy.pause(hard=True)
   
# You can drink something in all three labels.

#----------------------------------------------

label trinken_unterwegs: # this is where people drink now
    if Wasser <= 90:
        if Wasserspeicher >= 1:
            $ Wasser += 20
            A "Das war erfrischend."
            if Wasser >= 100:
                $ Wasser = 100
                return
            else:
                return
        else:
            A "Wir haben nicht mehr genügend Wasser! Wir sollten unser Wasservorrat auffüllen!"
            return
    else:
        A "Ich habe im momment kein durst."
        return
       
        # and now I want to go back to the label where I pressed the image button. For example label 2.
#--------------------------------------------------------
if I adapt the code now, imagebutton: action Jump ("drink_unterwegs")
And "call screen game_navigation"
I end up with the right label but not at the beginning of the label. But behind the call screen game_navigation
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,364
15,281
I end up with the right label but not at the beginning of the label. But behind the call screen game_navigation
And it will will always, whatever you try. Ren'py have no reason, and therefore will not, restart a label out of nowhere.
But I fail to see the issue. You want to return at the start of the label once the player is sent back out of the screen ? Well, just do it with a jump.


This being said, it looks more like a design issue.
I mean, as you explained it, it's both an optional action and a loop that wouldn't have an exit condition, that will be duplicated more than once. And this make no sense.

It looks like you're trying to do something like that:
Python:
label someRegularLabel:
   # whatever regular statements
   jump optionalDrink1

label someOtherRegularLabel:
   # whatever regular statements
   jump optionalDrink2

label optionalDrink1:
    call screen myOptinalDrinkMenu
    jump optionalDrink1

label optionalDrink2:
    call screen myOptinalDrinkMenu
    jump optionalDrink2
But at no time you talk about an exit condition.

Plus, there's no need to duplicate the "optionalDrink" part. You can perfectly have something that would looks like:
Python:
label someRegularLabel:
   # whatever regular statements
   call optionalDrink
   # whatever you want here

label someOtherRegularLabel:
   # whatever regular statements
   call optionalDrink
   # whatever you want here

label optionalDrink:
    call screen myOptinalDrinkMenu
    if exitCondition:
        return
    jump optionalDrink
I would also say that this could be done with extended menus. But I still don't understand what you need so much intermediate screens so I can be wrong.
And anyway it would be advanced coding, and so far you don't seem to be ready for this. What isn't a criticism and is perfectly fine, no one have the obligation to be more than an amateur. It's just that you wouldn't understand it and fail to apply it to your case.
 

Evildad

Member
Jan 7, 2019
113
218
Apparently my translation is too incomprehensible.
It is not meant badly but none of it really helped me.

I got help elsewhere and they understood straight away and the solution was as simple as expected.
Nevertheless, thank you for your efforts.