Lua:messageDialog

From Cheat Engine
(Redirected from messageDialog)
Jump to navigation Jump to search

<> Lua API Reference

function messageDialog(text) : integer

<> Lua API Reference

function messageDialog(text, type, buttons...) : integer

<> Lua API Reference

function messageDialog(title, text, type, buttons...) : integer

Shows a message dialog.

messageDialog can show a simple information dialog, or a dialog with a specific icon/sound and custom buttons. The overload with title allows setting a custom dialog title.

Function Parameters[edit]

Parameter Type Description
title String OPTIONAL The custom title shown in the dialog caption.
text String The message text shown in the dialog.
type MessageType The dialog type. This controls the icon and sound.
buttons MessageButton ... One or more button constants, such as mbOK, mbYes, or mbNo.

Returns[edit]

Integer — The modal result of the button that was pressed.

Message Types[edit]

Constant Description
mtWarning Shows a warning dialog.
mtError Shows an error dialog.
mtInformation Shows an information dialog.
mtConfirmation Shows a confirmation dialog.
mtCustom Shows a custom dialog type.

Button Constants[edit]

Constant Description
mbOK Adds an OK button.
mbCancel Adds a Cancel button.
mbYes Adds a Yes button.
mbNo Adds a No button.
mbAbort Adds an Abort button.
mbRetry Adds a Retry button.
mbIgnore Adds an Ignore button.
mbAll Adds an All button.
mbNoToAll Adds a No to All button.
mbYesToAll Adds a Yes to All button.
mbHelp Adds a Help button.
mbClose Adds a Close button.

Common Modal Results[edit]

Constant Description
mrOK The OK button was pressed.
mrCancel The Cancel button was pressed.
mrYes The Yes button was pressed.
mrNo The No button was pressed.
mrAbort The Abort button was pressed.
mrRetry The Retry button was pressed.
mrIgnore The Ignore button was pressed.
mrAll The All button was pressed.
mrNoToAll The No to All button was pressed.
mrYesToAll The Yes to All button was pressed.
mrClose The Close button was pressed.

Examples[edit]

Show a simple information dialog[edit]

1 messageDialog("Operation completed")

Show an information dialog with an OK button[edit]

1 messageDialog("Operation completed", mtInformation, mbOK)

Show a warning dialog[edit]

1 messageDialog("This action may be unsafe", mtWarning, mbOK)

Show an error dialog[edit]

1 messageDialog("The operation failed", mtError, mbOK)

Show a confirmation dialog[edit]

1 local result = messageDialog("Do you want to continue?", mtConfirmation, mbYes, mbNo)
2 
3 if result == mrYes then
4   print("User selected Yes")
5 else
6   print("User selected No")
7 end

Use a custom dialog title[edit]

1 local result = messageDialog("Confirm Action", "Apply the selected changes?", mtConfirmation, mbYes, mbNo, mbCancel)
2 
3 if result == mrYes then
4   print("Applying changes")
5 elseif result == mrNo then
6   print("Changes skipped")
7 else
8   print("Action cancelled")
9 end

Ask before deleting records[edit]

1 local result = messageDialog("Delete selected records?", mtConfirmation, mbYes, mbNo)
2 
3 if result == mrYes then
4   AddressList.deleteSelected()
5 end

Ask before disabling records[edit]

1 local result = messageDialog("Disable all records without executing disable sections?", mtWarning, mbYes, mbNo)
2 
3 if result == mrYes then
4   AddressList.disableAllWithoutExecute()
5 end

Use Retry and Cancel[edit]

1 local result = messageDialog("Could not open the process", mtError, mbRetry, mbCancel)
2 
3 if result == mrRetry then
4   print("Retrying")
5 else
6   print("Cancelled")
7 end

Wrap messageDialog in a helper function[edit]

1 local function confirm(text)
2   return messageDialog(text, mtConfirmation, mbYes, mbNo) == mrYes
3 end
4 
5 if confirm("Enable this script?") then
6   print("Confirmed")
7 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine