Gui.get_font additional usage (CLOSED)

Greetings,

I ran into an issue with the gui.get_font function when I was trying to get the font itself within the gui object. I quickly understood that the way in which I was trying to use the function was incorrect, due to the fact that it’s supposed be used in reference to text nodes and to return the font used. I would like to suggest an additional usage, ex:

font = gui.get_font("myFont") -- myFont being located in the Fonts section of the gui object, instead of in Nodes

Hope I’m not missing anything that should be obvious.

Edit: I worked around this by getting the font of one of my constant objects which has the font I wanted to use, but it would be logical to be able to call the font itself as well so that it couldn’t become nil.

gui.get_font()returns the id of the font set on a text node:

local text_node = gui.get_node("my_text_node")
local font_id = gui.get_font(text_node)
	
print(font_id) --> DEBUG:SCRIPT: hash: [system_font]

If you want to set the font of a node, you don’t have to get the id first, just provide the id of the font that you set in the editor as a hash or a string:

local some_node = gui.get_node("text")
gui.set_font(some_node, hash("source_sans"))

3 Likes

Ah, I see! Thank you.

1 Like