How to execute a textbutton's action when the textbutton is selected (not hovered)?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

How to execute a textbutton's action when the textbutton is selected (not hovered)?

#1 Post by henvu50 »

This code shows a list of textbutton's. If you press the W or S keys, it will cause the textbutton's to become selected, indicated by the green color. If you press the arrow keys or move the mouse over the textbutton, it will trigger its hovered state (RED color).

When the textbutton is hovered, you can press the enter key and it will trigger its action.

But how can you make it so enter key triggers selected state, but without overriding Ren'py's control of the select key; that means I don't want to use KEY, because that will create extra work)?
wt33.jpg

Code: Select all

default listOfButtonIndex = 0
init python:
    def incIt():
        global listOfButtonIndex
        listOfButtonIndex += 1
        print listOfButtonIndex
    def decIt():
        global listOfButtonIndex
        listOfButtonIndex -= 1
        print listOfButtonIndex

screen listOfButtons():
    key "w" action Function(decIt)
    key "s" action Function(incIt)
    vbox:
        for i in range(0, 10):
            textbutton str(i):
                xpos 200
                ypos 200
                style "some_style12"
                text_style "some_style12"
                #action [SetVariable("listOfButtonIndex", i), Show('test214')]
                action [SelectedIf(SetVariable("listOfButtonIndex", i)), SetVariable("listOfButtonIndex", i), Show('test214') ]

style some_style12:
    idle_color "#555555"
    hover_color "#FF0000"
    selected_color "#1fff00"

screen test214():
    text "test"
screen waitit():
    pass
label start:
    show screen listOfButtons
    call screen waitit
    jump start
    return
    
Last edited by henvu50 on Tue Jul 20, 2021 4:57 am, edited 4 times in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3784
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is it possible to run an action when a displayable is focused (not hovered)?

#2 Post by Imperf3kt »

Completely blind guess here, I have no knowledge of this particular subject, but I would guess this may be related?
https://www.renpy.org/doc/html/screen_p ... t_selected

Or perhaps
https://www.renpy.org/doc/html/screen_p ... s_selected
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Google [Bot]