Imagebutton ATL resets when clicking anywhere

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
linkaegar
Newbie
Posts: 2
Joined: Tue Sep 18, 2018 4:56 am
Contact:

Imagebutton ATL resets when clicking anywhere

#1 Post by linkaegar »

I was following Mugen's Imagebutton tutorial and wanted to see if I could recreate parts of it. In screens.rpy, I made an imagebutton with a transformation that moves left and right and, when clicked on, sets a boolean variable clicked_on_button to true (originally initialized as false). Here's the code for it.

Code: Select all

screen say(who, what):
    ... # All the other pre-written code unrelated to this.
    
    if show_pointclick2:
        use pointclick2()
#end screen say

init -2 python:
    show_pointclick2 = False
    clicked_on_button = False

screen pointclick2():
    # Upon clicking on this button, jump to label button_pressed and change clicked_on_button to true. There might be some redundancy here.
    
    imagebutton auto "gui/renpyicon_%s.png" action Jump("button_pressed") xpos 0 ypos 0 focus_mask True at my_movement clicked [SetVariable("clicked_on_button", True)]

init -2:
    transform my_movement:
        xalign 0.1 yalign 0.5
        linear 10.0 xalign 1.0	
        linear 10.0 xalign 0.1
        repeat
In my script.rpy, I had this code to test it out.

Code: Select all

    $ show_pointclick2 = True
    h "Try clicking on the button as it moves."

    # If the user missed clicking on the moving button, say "too slow" and loop until they do press on it successfully. 
    
    while not clicked_on_button:
        h "Too slow!"

    label button_pressed:

    $ show_pointclick2 = False

    h "You did it!"
The problem that I have is, whenever the user does not manage to click on the imagebutton, the system does say "Too slow!", but the animation for the imagebutton resets whenever it happens. For example, if the imagebutton is in the middle of the screen and the user doesn't manage to click on it, the button immediately snaps back to its starting position on the left and the animation starts over. Is there anyway to stop the button from resetting upon every click? I'm assuming it has something to do with either the imagebutton properties or the while-loop.

Any help is appreciated!

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Imagebutton ATL resets when clicking anywhere

#2 Post by philat »

Don't put it in the say screen, basically.

Code: Select all

default clicked_on_button= False

label start:
    show screen temp
    pause

    while not clicked_on_button:
        "False"
    "True."

screen temp():
    textbutton "click me" action [SetVariable("clicked_on_button", True), Return(), Hide("temp")] at my_movement

linkaegar
Newbie
Posts: 2
Joined: Tue Sep 18, 2018 4:56 am
Contact:

Re: Imagebutton ATL resets when clicking anywhere

#3 Post by linkaegar »

philat wrote: Tue Sep 18, 2018 9:20 pm Don't put it in the say screen, basically.
That did the trick! Thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]