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.
Let's say you have four image buttons, and you want the hover state of all of them to trigger when one imagebutton is hovered. Is using a boolean variable, hovered and unhovered the best way to achieve this? Like this?
# if any of the displayables are hovered, set this variable to true, if unhovered, set this variable to false
default anyButtonsHovered= False
screen test():
imagebutton:
# give the illusion that this is hovered by showing the hover image as idle
if anyButtonsHovered:
idle "1_hover.png"
else:
idle "1_idle.png" # show normal idle
hover "1_hover.png"
hovered SetVariable("anyButtonsHovered", True)
unhovered SetVariable("anyButtonsHovered", False)
action NullAction()
textbutton "Text":
hovered SetVariable("anyButtonsHovered", True)
unhovered SetVariable("anyButtonsHovered", False)
if anyButtonsHovered:
text_outlines [ (3, "#000000", 0, 0) ] #give the illusion that this is hovered by showing outlines for the text
else:
text_outlines [ (0, "#000000", 0, 0) ]
action NullAction()
imagebutton:
if anyButtonsHovered:
# give the illusion that this is hovered
idle "1_hover.png"
else:
idle "1_idle.png"
hover "1_hover.png"
hovered SetVariable("anyButtonsHovered", True)
unhovered SetVariable("anyButtonsHovered", False)
action NullAction()
I was wondering if there was a better way to do this?
Last edited by henvu50 on Fri Jul 16, 2021 5:16 pm, edited 1 time in total.
The question is why do you need this?
Hovered state is really means that button is hovered by mouse pointer or selected via gamepad or keyboard. Normally, you unable to click two not overlapped buttons by single mouse pointer... So, you want to use this feature for something that it's not suited for, that's why it looks buggy/inconvenient.
Also, there's a 'selected' state for the button - this might be the thing you need.
Here's some useful information about button's behavior - viewtopic.php?f=8&t=26492#p322596
Alex wrote: ↑Thu Jul 15, 2021 5:25 pm
The question is why do you need this?
In my game you can travel from room to room. You can do this by either clicking the image in the room, or clicking another image in a navigation wheel that represents that room. So there's two imagebuttons that do the same thing. I want both of their hover state to trigger if either one is hovered.
Hovered state is really means that button is hovered by mouse pointer or selected via gamepad or keyboard. Normally, you unable to click two not overlapped buttons by single mouse pointer... So, you want to use this feature for something that it's not suited for, that's why it looks buggy/inconvenient.
Also, there's a 'selected' state for the button - this might be the thing you need.
Here's some useful information about button's behavior - viewtopic.php?f=8&t=26492#p322596
Hmmm, the latter solution could work. i've worked with that method actually. Hmmm good thinking. I'll try that. It would be nice if there was an easy way to just control any displayable's state with one line of python code.
I ended up relying on flags to control the hover state of other displayables.
Okay, one more thing.
In a point and click game, you have interactables (npc's or objects) in the scene. I want to create an action that will trigger the hover state of a certain group of displayables, by id or tag. When the user presses this button, they can see what items can be interacted with in the scene.
So with one line, you can select a group of displayables and just set their hover state to true. I bet renpy can do stuff like that, but I can't figure out how to do it.
henvu50 wrote: ↑Fri Jul 16, 2021 2:03 pm
...So with one line, you can select a group of displayables and just set their hover state to true. I bet renpy can do stuff like that...
You can use variables to set selected state of your displayables. So, if several displayables uses the same variable they all will be set as selected.
When you add displayables to the screen you can set what variable they will use (so you don't need to get the id). This might be a property of your displayables that set for one of those variables, but this depends of how you've designed them.
Sample