Hi everyone,
I am trying to use renpy.focus_coordinates() function in screens language but it doesn't work the way as I assumed it would.
It says-
This attempts to find the coordinates of the currently-focused displayable. If it can, it will return them as a (x, y, w, h) tuple. If not, it will return a (None, None, None, None) tuple..
Here is the code:
screen TestScreen():
default button_xpos = 0
textbutton "Get Xpos" xalign 0.5 yalign 0.5:
action SetScreenVariable("button_xpos", renpy.focus_coordinates()[0]) #On click it should set the xpos of the focused button
text "Coordinates - [button_xpos]" xalign 0.5 yalign 0.3 #Display the button's coordinates
textbutton "Return" xalign 0.5 yalign 0.8:
action Return()
label start:
call screen TestScreen
$ renpy.pause(hard=True)
return
Problem is that the button is focused when I hover with mouse or keyboard and once it is clicked, it displays the result as "None" but when I click again, then on the second time it will show correct xpos of the button. Why can't I get the right xpos result on the first time when clicking?
[Solved]Issue with "renpy.focus_coordinates()"
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.
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.
[Solved]Issue with "renpy.focus_coordinates()"
Last edited by Dark79 on Wed Dec 15, 2021 3:09 pm, edited 1 time in total.
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Issue with "renpy.focus_coordinates()"
The value of a screen action is evaluated when the screen is shown (not when the click occurs)
You could maybe do it through a Function call...
You could maybe do it through a Function call...
Code: Select all
init python:
def set_button_xpos():
cs = renpy.current_screen()
if cs is None:
return
cs.scope["button_xpos"] = renpy.focus_coordinates()[0]
renpy.restart_interaction()
...
action Function(set_button_xpos)
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Issue with "renpy.focus_coordinates()"
Thank you so much for the fast reply and solution, this actually works. Not exactly sure what is going on here ( never checked renpy.current_screen() & renpy.restart_interaction() ) but it works.Remix wrote: ↑Wed Dec 15, 2021 2:21 pm The value of a screen action is evaluated when the screen is shown (not when the click occurs)
You could maybe do it through a Function call...
Code: Select all
init python: def set_button_xpos(): cs = renpy.current_screen() if cs is None: return cs.scope["button_xpos"] = renpy.focus_coordinates()[0] renpy.restart_interaction() ... action Function(set_button_xpos)
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: [Solved]Issue with "renpy.focus_coordinates()"
Because you are using a screen variable (rather than global) we need to target the screen itself... so
renpy.current_screen().scope["screen variable name"]
is what we use there.
We use renpy.restart_interaction() at the end to effectively just redraw the screen, so the text "Coordinates - [button_xpos]" bit updates
renpy.current_screen().scope["screen variable name"]
is what we use there.
We use renpy.restart_interaction() at the end to effectively just redraw the screen, so the text "Coordinates - [button_xpos]" bit updates
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: [Solved]Issue with "renpy.focus_coordinates()"
Thanks for explaining more clearly. I have tried to place variable "button_xpos" outside of the screen and use SetVariable() instead of SetScreenVariable(), but I got the same result. So far I used global variables while placing them inside the def functions.Remix wrote: ↑Wed Dec 15, 2021 3:15 pm Because you are using a screen variable (rather than global) we need to target the screen itself... so
renpy.current_screen().scope["screen variable name"]
is what we use there.
We use renpy.restart_interaction() at the end to effectively just redraw the screen, so the text "Coordinates - [button_xpos]" bit updates
But as much I understand I don't need to use renpy.current_screen() to access those variables that are outside from screen.
I have tried to find more info about renpy.current_screen() but it seems to be nowhere in the documentations.
Who is online
Users browsing this forum: rag_exe21