Difference between revisions of "Lua:messageDialog"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' messageDialog(''Text'', ''Type'', ''Button'', ...)
+
{{CodeBox|'''function''' messageDialog(''text'') ''':''' integer}}
  
Displays a messagebox of a specific type with a variable amount of buttons at the center of the screen with the provided text.
+
{{CodeBox|'''function''' messageDialog(''text'', ''type'', ''buttons''...) ''':''' integer}}
  
Returns: [[ButtonResult]]
+
{{CodeBox|'''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===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!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
+
|type
|[[DialogType]]
+
|MessageType
|The type of the messagebox.
+
|The dialog type. This controls the icon and sound.
 
|-
 
|-
|Button
+
|buttons
|[[ButtonType]]
+
|MessageButton ...
|The kind of button. There can be multiple buttons provided
+
|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.
 +
|}
  
{{LuaSeeAlso}}
+
===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.
 +
|-
 +
|mrNoToAll
 +
|The No to All button was pressed.
 +
|-
 +
|mrYesToAll
 +
|The Yes to All button was pressed.
 +
|-
 +
|mrClose
 +
|The Close button was pressed.
 +
|}
 +
 
 +
===Examples===
 +
 
 +
====Show a simple information dialog====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
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)
  
== '''==EXAMPLES== by CHEATS GAMES''' ==
+
if result == mrYes then
 +
  print("Applying changes")
 +
elseif result == mrNo then
 +
  print("Changes skipped")
 +
else
 +
  print("Action cancelled")
 +
end
 +
</syntaxhighlight>
  
 +
====Ask before deleting records====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Delete selected records?", mtConfirmation, mbYes, mbNo)
  
'''messageDialog("NÃO NOS RESPONSABILIZAMOS POR BANIMENTOS\nCONTINUAR?", mtInformation, mbYes,mbNo)
+
if result == mrYes then
 +
  AddressList.deleteSelected()
 +
end
 +
</syntaxhighlight>
  
MessageDialog('Do you really want to continue?', mtConfirmation, mbYes, mbNo, mbCancel, 0)
+
====Ask before disabling records====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Disable all records without executing disable sections?", mtWarning, mbYes, mbNo)
  
messageDialog("NÃO NOS RESPONSABILIZAMOS POR BANIMENTOS\nCONTINUAR?", mtError, mbYes,mbNo)
+
if result == mrYes then
 +
  AddressList.disableAllWithoutExecute()
 +
end
 +
</syntaxhighlight>
  
messageDialog("POR FAVOR SELECIONE O PROCESSO CORRETO", mtError, mbOK)
+
====Use Retry and Cancel====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local result = messageDialog("Could not open the process", mtError, mbRetry, mbCancel)
  
messageDialog("BEM VINDO!\nBY RAFAEL LIMA!", mtInformation, mbYes,mbOK)
+
if result == mrRetry then
 +
  print("Retrying")
 +
else
 +
  print("Cancelled")
 +
end
 +
</syntaxhighlight>
  
messageDialog(mtError,'do i have?','Title',mbOK)
+
====Wrap messageDialog in a helper function====
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local function confirm(text)
 +
  return messageDialog(text, mtConfirmation, mbYes, mbNo) == mrYes
 +
end
  
messageDialog('Custom dialog',mtCustom,mbYes,mbOK)
+
if confirm("Enable this script?") then
 +
  print("Confirmed")
 +
end
 +
</syntaxhighlight>
  
messageDialog(None,'do i have?','Title')
+
{{LuaSeeAlso}}
'''
 

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