Does anyone have a good popup messagebox routine? Below is the one I used in 3.5 that doesn't work in 4.0.

func alert(text: String, title: String='Message') -> void:
	# credit for original code to: https://gamedev.stackexchange.com/users/135571/hola
	# https://gamedev.stackexchange.com/questions/177723/simple-message-box-in-gdscript-godot?newreg=265dab057bb6497a98f510e6efa3ae85
	var dialog = AcceptDialog.new()
	dialog.dialog_text = text
	dialog.window_title = title
	dialog.connect('modal_closed', Callable(dialog, 'queue_free'))
	add_child(dialog)
	dialog.popup_centered()
  • xyz replied to this.

    xyz Ok, I'm a dingbat. All I had to do was change
    dialog.window_title = title
    to
    dialog.title = title

    ...thanks for making me go back and take a closer look.

      grymjack For those that are interested, here is the function. I also added an extra parameter that will allow you to pass in a Vector2 to control the dialog size.

      func alert(text: String, title: String='Message',dialog_size=Vector2(200, 100)) -> void:
      	# credit for original code to: https://gamedev.stackexchange.com/users/135571/hola
      	# https://gamedev.stackexchange.com/questions/177723/simple-message-box-in-gdscript-godot?newreg=265dab057bb6497a98f510e6efa3ae85
      	var dialog = AcceptDialog.new()
      	dialog.dialog_text = text
      	dialog.title = title
      	dialog.connect('modal_closed', Callable(dialog, 'queue_free'))
      	dialog.size = dialog_size
      	dialog.get_child(1, true).horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
      	add_child(dialog)
      	dialog.popup_centered()
      5 days later

      is there a way to style this dialog?