I need help with imagebuton

Dec 3, 2019
28
23
I just found out about this yesterday, so I know nothing about it.
I have 2 buttons on my screen, which I added with something like
screen blahblah():
vbox ..... spacing...
imagebutton:
action
imagebutton:
action
show screen blahblah

Ok, now I have 2 buttons on my screen, I can click on them and they will do their actions.
But I want to hide one of the imagebutton after clicking on it. is it possible? I can do this only by adding each of the buttons with their own screen.
And the second question. Is it possible to have a different action on the first click, second, third and so on? Or I'll have to hide the used button and put a new one , with a different action, in its place.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,692
Maybe this could help:

Python:
default button1_var = 0
default button2_var = 0


screen blahblah:
     vbox:
          spacing 20

          if button1_var == 0:
               imagebutton auto "button1_%s.png" focus_mask True action SetVariable("button1_var", +1), Jump("label_1")

          imagebutton auto "button2_%s.png" focus_mask True action SetVariable("button2_var", +1), Jump("label_2")        


label label_1:
    "..."

label label_2:
     if button2_var == 1:
          "..."
     if button2_var == 2:
          "..."
     if button2_var == 3:
          "..."
"button1_var" controls whether the first button is displayed or not; if the variable is not 0 it will not be displayed anymore.

"button2_var" controls the action of the second button; when it jumps to a label, depending on its value, one thing or another happens.
 
Dec 3, 2019
28
23
Thank you, I’ll try to figure it out somehow.
And I have another question.
There is a sequence of scenes a1-a10, in a scene a1 appears a button with an action X, in scene a10 it disappears. I want to make it so that if I press button at any time between a1-a10, I will be shown this action X, and after I would return at the moment of pressing a button. Button is disappearing.
My blunt solutuion is:
Python:
screen ButtonX():
    imagebutton:
        xalign 1.0
        yalign 0.0
        idle "image.png" hover "inageh.png"
        action Show("ActionX")

screen ActionX():
    modal True #I don't know what is this, but I saw it in the example
    imagemap:
        ground "ActionX.png"
        hotspot(entire screen) action Hide("ActionX")
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,692
Maybe...
Python:
screen actionX:
     imagebutton auto "button_actionX_%s.png" focus_mask True action Call("DoActionX")  ### Making a "call" will return you to the previous point where you were

label myscene:
     show screen actionX   ### shows the screen
     scene image_a1
     "..."
     scene image_a2
     "..."
     scene image_a3
     "..."
     scene image_a4
     "..."
     scene image_a5
     "..."
     scene image_a6
     "..."
     scene image_a7
     "..."
     scene image_a8
     "..."
     scene image_a9
     "..."
     scene image_a10
     "..."
     hide screen actionX   ### hides the screen


label DoActionX:
     "...."   ## the X action
     return
Not tested :p

BTW, "modal True" is to prevent the player from clicking outside the "screen"; in your case you are not interested since you want the player to be able to follow the sequence, whether or not that player presses the screen button.
 
  • Like
Reactions: Yuri L
Dec 3, 2019
28
23
You don't have permission to view the spoiler content. Log in or register now.

Thanks again, but its not working. Dut I managed to do it with my "stone Age" method.
Python:
screen ButtonX():
    imagebutton:
        xalign 1.0
        yalign 0.5
        idle "bl.png" hover "blh.png"
        action Call("ActionX")#I didn't know that a Call could do this.
        
show screen ButtonX
scene a1-a10
hide screen ButtonX

label ActionX():
    show 334
    with dissolve
    hide screen ButtonX
    $ choices.append("choice")
    "Blah Blah"
    hide 334
    return
 
  • Haha
Reactions: Porcus Dev

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,692
Well, I couldn't test it, but the code you wrote is more or less the same, different ways of writing it :p;)
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,692
Maybe the problem was not hiding the screen shown

Python:
screen actionX:
     imagebutton auto "button_actionX_%s.png" focus_mask True action Hide("actionX"), Call("DoActionX")
 

9thCrux

--Waifu maker--
Game Developer
Oct 22, 2017
844
3,221
Maybe this could help:

Python:
default button1_var = 0
default button2_var = 0


screen blahblah:
     vbox:
          spacing 20

          if button1_var == 0:
               imagebutton auto "button1_%s.png" focus_mask True action SetVariable("button1_var", +1), Jump("label_1")

          imagebutton auto "button2_%s.png" focus_mask True action SetVariable("button2_var", +1), Jump("label_2")   


label label_1:
    "..."

label label_2:
     if button2_var == 1:
          "..."
     if button2_var == 2:
          "..."
     if button2_var == 3:
          "..."
"button1_var" controls whether the first button is displayed or not; if the variable is not 0 it will not be displayed anymore.

"button2_var" controls the action of the second button; when it jumps to a label, depending on its value, one thing or another happens.

0o

That jump("label_1") is something I have been looking for...

Can you actually do a jump from inside a screen?

jump is like "go there never comeback"... I think.

I mean; if I do a call screen from within a label and then I use jump to go to another label would that work?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,369
15,286
Python:
     imagebutton auto "button_actionX_%s.png" focus_mask True action Call("DoActionX")  ### Making a "call" will return you to the previous point where you were
Call should return you outside of the screen. But among the possible workaround, there's this one :
Python:
screen a1():
     # Pass the name of the actual screen as parameter.
     imagebutton auto "button_actionX_%s.png" focus_mask True action Call( "DoActionX", "a1" )

screen a2():
     imagebutton auto "button_actionX_%s.png" focus_mask True action Call( "DoActionX", "a2" )
[...]
screen a10():
     imagebutton auto "button_actionX_%s.png" focus_mask True action Call( "DoActionX", "a10" )

[...]
label DoActionX( retScreen ):
    # It need to be a called label because of the parameter.
    # But this imply that we need to remove the return point
    # from the stack.
    $ renpy.pop_call()
    # Then the scene play as usual.
    scene whatever
    "blablabla"
    [...]
    # And finally we return to the screen.
    # /call screen/ do not works with an /expression/, therefore
    # the Python equivalent is needed.
    $ renpy.call_screen( retScreen )


I mean; if I do a call screen from within a label and then I use jump to go to another label would that work?
Yes. Like I said the other time, called screen aren't like called label. They don't generate a return point, they just wait until something send the game outside of the screen ; generally it's either a , a or a screen action.
 
Dec 3, 2019
28
23
Another question, maybe there is an easy way to add a text near a button when it's hovered?

I tried to do it with mtt.Action ( I have no idea what is it, but I saw how it works ) but it didn't work for me.