Difference between revisions of "Lua:messageDialog"

From Cheat Engine
Jump to navigation Jump to search
(Removed whatever the spanish person did and updated the entry.)
(Major overhaul of the post.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' messageDialog(''Text'', ''Type'', ''Button'', ...) ''':''' [[ButtonResult]]
+
{{CodeBox|'''function''' messageDialog(''text'') ''':''' integer}}
  
'''function''' messageDialog(''Title'', ''Text'', ''Type'', ''Button'', ...) ''':''' [[ButtonResult]]
+
{{CodeBox|'''function''' messageDialog(''text'', ''type'', ''buttons''...) ''':''' integer}}
  
'''function''' messageDialog(''Text'') ''':''' [[ButtonResult]]
+
{{CodeBox|'''function''' messageDialog(''title'', ''text'', ''type'', ''buttons''...) ''':''' integer}}
  
Displays a message box at the center of the screen with the provided text, icon, and buttons. 
+
Shows a message dialog.
You can specify a custom title, dialog type, and any combination of buttons. 
 
If only ''Text'' is provided, an information dialog with an OK button is shown.
 
 
 
Returns: [[ButtonResult]]
 
  
 +
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===
 
===Function Parameters===
Line 19: Line 16:
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|Text
+
|title
 +
|String OPTIONAL
 +
|The custom title shown in the dialog caption.
 +
|-
 +
|text
 
|String
 
|String
|The message to show.
+
|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===
 +
Integer — The modal result of the button that was pressed.
 +
 
 +
===Message Types===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!style="width: 80%;background-color:white;" align="left"|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===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!style="width: 80%;background-color:white;" align="left"|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===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!style="width: 80%;background-color:white;" align="left"|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.
 
|-
 
|-
|Title
+
|mrNoToAll
|String
+
|The No to All button was pressed.
|The title of the message box (optional; only for the 2nd syntax).
 
 
|-
 
|-
|Type
+
|mrYesToAll
|[[DialogType]]
+
|The Yes to All button was pressed.
|The type of the message box (icon/sound).
 
 
|-
 
|-
|Button
+
|mrClose
|[[ButtonType]]
+
|The Close button was pressed.
|The kind of button. There can be multiple buttons provided.
 
 
|}
 
|}
  
 
===Examples===
 
===Examples===
<pre>
 
-- Show a simple information dialog with default OK button
 
messageDialog("Welcome to Cheat Engine!")
 
</pre>
 
  
<pre>
+
====Show a simple information dialog====
-- Show a confirmation dialog with Yes and No buttons
+
<syntaxhighlight lang="lua" line highlight="1">
local result = messageDialog("Do you want to save changes?", mtConfirmation, mbYes, mbNo)
+
messageDialog("Operation completed")
 +
</syntaxhighlight>
 +
 
 +
====Show an information dialog with an OK button====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
messageDialog("Operation completed", mtInformation, mbOK)
 +
</syntaxhighlight>
 +
 
 +
====Show a warning dialog====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
messageDialog("This action may be unsafe", mtWarning, mbOK)
 +
</syntaxhighlight>
 +
 
 +
====Show an error dialog====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
messageDialog("The operation failed", mtError, mbOK)
 +
</syntaxhighlight>
 +
 
 +
====Show a confirmation dialog====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Do you want to continue?", mtConfirmation, mbYes, mbNo)
 +
 
 +
if result == mrYes then
 +
  print("User selected Yes")
 +
else
 +
  print("User selected No")
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Use a custom dialog title====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Confirm Action", "Apply the selected changes?", mtConfirmation, mbYes, mbNo, mbCancel)
 +
 
 
if result == mrYes then
 
if result == mrYes then
   print("User chose Yes")
+
   print("Applying changes")
 +
elseif result == mrNo then
 +
  print("Changes skipped")
 
else
 
else
   print("User chose No or closed the dialog")
+
   print("Action cancelled")
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Ask before deleting records====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Delete selected records?", mtConfirmation, mbYes, mbNo)
 +
 
 +
if result == mrYes then
 +
  AddressList.deleteSelected()
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Ask before disabling records====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Disable all records without executing disable sections?", mtWarning, mbYes, mbNo)
 +
 
 +
if result == mrYes then
 +
  AddressList.disableAllWithoutExecute()
 
end
 
end
</pre>
+
</syntaxhighlight>
  
<pre>
+
====Use Retry and Cancel====
-- Show an error dialog with a custom title and OK button
+
<syntaxhighlight lang="lua" line highlight="1">
messageDialog("Critical Error", "A fatal error has occurred.", mtError, mbOK)
+
local result = messageDialog("Could not open the process", mtError, mbRetry, mbCancel)
</pre>
 
  
<pre>
+
if result == mrRetry then
-- Show a warning dialog with Yes, No, and Cancel buttons
+
   print("Retrying")
local res = messageDialog("Delete this file?", mtWarning, mbYes, mbNo, mbCancel)
 
if res == mrYes then
 
  print("File will be deleted.")
 
elseif res == mrNo then
 
   print("File will not be deleted.")
 
 
else
 
else
   print("Operation cancelled.")
+
   print("Cancelled")
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Wrap messageDialog in a helper function====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local function confirm(text)
 +
  return messageDialog(text, mtConfirmation, mbYes, mbNo) == mrYes
 
end
 
end
</pre>
 
  
<pre>
+
if confirm("Enable this script?") then
-- Show a help dialog with Help and Close buttons
+
  print("Confirmed")
messageDialog("Help", "For more information, visit the documentation.", mtInformation, mbHelp, mbClose)
+
end
</pre>
+
</syntaxhighlight>
  
== See also ==
+
{{LuaSeeAlso}}
* [[ButtonResult]]
 
* [[DialogType]]
 
* [[ButtonType]]
 
* [[showMessage]]
 

Latest revision as of 20:22, 25 June 2026

<> 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