I want a single line of code which shows a popup dialog with the words "Hello World!" and an "Ok" button. (I want something simple for now, I know how to make something more complicated but that would be stupid at this point in development).
\$\begingroup\$
\$\endgroup\$
2
-
\$\begingroup\$ Hi Strategy Thinker, have you searched for any Godot tutorials? Last time I searched online, I found more than enough sites with helpful content. \$\endgroup\$– Tom TsagkatosCommented Dec 13, 2019 at 11:54
-
2\$\begingroup\$ @TomTsagk Before posting this question I searched for "godot message box", "godot dialogue tutorial", "godot message to user", "godot popup message to user", "godot pupup dialog example", "godot display message on screen", "godot messagebox show", "godot message box show" \$\endgroup\$– Strategy ThinkerCommented Dec 14, 2019 at 23:05
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
1
You can use the OS / platform's alert
system:
OS.alert('This is your message', 'Message Title')
You can use WindowDialog
or subclass on any node like this:
func alert(text: String, title: String='Message') -> void:
var dialog = AcceptDialog.new()
dialog.dialog_text = text
dialog.window_title = title
dialog.connect('modal_closed', dialog, 'queue_free')
add_child(dialog)
dialog.popup_centered()
You can do the above, but globally:
func alert(text: String, title: String='Message') -> void:
# ... code from above, but instead of `add_child(dialog)` do
var scene_tree = Engine.get_main_loop()
scene_tree.current_scene.add_child(dialog)
dialog.popup_centered()
-
1\$\begingroup\$ Excellent answer, it had never occurred to me to connect a runtime spawned object directly to the queue_free method before, so simple! \$\endgroup\$– GilesCommented Jan 2, 2022 at 14:09