Getting Screen Width and Height Outside of Render Script

I know that the render script receives messages when the window is resized, but I require the current screen size inside a game object script.

Is there any way to retrieve the current screen size from a game object script?

I need this so that I can accurately transform the mouse position to a position in the game world

1 Like

One solution would be that you create a Lua module and require it from your render script, store the results from render.get_window_width()/height() inside that module and then require it from other places and read back the values.

You could also set up a publish/subscribe system either using function callbacks or message passing between the render script and interested parties.

You also have window.set_listener().

3 Likes

Britzl is it just me or are lua modules your new solution to everything? hahaha

1 Like

:slight_smile: Yeah, maybe it is! But it’s not a new solution. I’ve always advocated the use of Lua modules when it makes sense to use them.

2 Likes

Yeah, modules if you love to code or just global var if you are a lazy ass like me and just want the damned thing done :slight_smile:

1 Like