How to make Button.text using TTF font by script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lejardo

I tried everyway I’v thought, and searched a long time here but without gook luck.
I just wanna change the Button, or Label, displaying font to a TTF, by scripts.
I tried these ways:

set("custom_fonts/font", load("res://FONT/mainmenu_button.ttf"))
add_font_override("custom_fonts/font",load("res://FONT/mainmenu_button.ttf"))
add_font_override("font",load("res://FONT/mainmenu_button.ttf"))
add_color_override("font_color", Color(1,0,0,1))
set("custom_fonts/font", load("res://FONT/mainmenu_button.ttf"))
set("custom_fonts/font", DynamicFont)
set("DynamicFontdata",load("res://FONT/mainmenu_button.ttf"))
set("font_data",load("res://FONT/mainmenu_button.ttf"))

The ttf font I wanna use is “res://FONT/mainmenu_button.ttf”.
I just can’t make it work.

Help me, plz.

:bust_in_silhouette: Reply From: flurick

Yeah completely undocumented, here is something that gets it done after some trial and error.

var path = "res://FONT/mainmenu_button.ttf"	
var new_font = DynamicFont.new()
var new_data = DynamicFontData.new()
new_data.font_path = path
new_font.font_data = new_data
set("custom_fonts/font", new_font)

It works perfect!
Thank you very much!

Lejardo | 2018-10-16 11:16