Canvas MessageBox

From FlightGear wiki
Revision as of 20:37, 24 June 2014 by Philosopher (talk | contribs) (→‎Examples: canvas.MessageBox.info -> canvas.MessageBox.information, looks good!)
Jump to navigation Jump to search
This article describes content/features that may not yet be available in the latest stable version of FlightGear (2020.3).
You may need to install some extra components, use the latest development (Git) version or even rebuild FlightGear from source, possibly from a custom topic branch using special build settings: .

This feature is scheduled for FlightGear 3.2. 100}% completed

If you'd like to learn more about getting your own ideas into FlightGear, check out Implementing new features for FlightGear.


Message boxes provide a simple way to report information and warnings or ask questions. In FlightGear 3.1+ using canvas.MessageBox with the Nasal scripting language, allows showing standard message boxes to the user.

Predefined Severity Levels/Icons

Icon Icon Name Standard MessageBox Description
Dialog-question.png "dialog-question"
canvas.MessageBox.question(
  <title>,
  <text>,
  cb = nil,
  buttons = canvas.MessageBox.Yes
          | canvas.MessageBox.No
);
Ask the user a (yes/no) question.
Dialog-info.png "dialog-info"
canvas.MessageBox.information(
  <title>,
  <text>,
  cb = nil,
  buttons = canvas.MessageBox.Ok
);
Show the user some information, with only the possiblity to close the dialog.
Dialog-warning.png "dialog-warning"
canvas.MessageBox.warning(
  <title>,
  <text>,
  cb = nil,
  buttons = canvas.MessageBox.Ok
);
Show the user a non critical warning, with only the possiblity to close the dialog.
Dialog-error.png "dialog-error"
canvas.MessageBox.critical(
  <title>,
  <text>,
  cb = nil,
  buttons = canvas.MessageBox.Ok
);
Notify the user of a critical error or failure, with only the possiblity to close the dialog.

Examples

Canvas-MessageBox-demo information.png
canvas.MessageBox.information("Success", "The operation has successfully completed.");
Canvas-MessageBox-demo question.png
canvas.MessageBox.question(
  "Do you want it?",
  "The question is: Do you want to get a real question?.",
  func(sel)
  {
    if( sel == canvas.MessageBox.Yes )
      print("I only know that the answer is 42.");
    else
      print("Ok, I will not give you a real question.");
  }
);
Canvas-MessageBox-demo warning dont-show-again.png
canvas.MessageBox.warning(
  "Warning...",
  "Have you read this warning? If you want it will not be shown again.",
  func(sel)
  {
    if( sel != canvas.MessageBox.Ok )
      return;

    print("You have been warned. Let the games begin...");
  },
    canvas.MessageBox.Ok
  | canvas.MessageBox.Cancel
  | canvas.MessageBox.DontShowAgain
);