Difference between revisions of "Lua:inputQuery"

From Cheat Engine
Jump to navigation Jump to search
m (Minor edit. Added Version Notice Template.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
 
{{VersionNotice|6.4+}}
 
{{VersionNotice|6.4+}}
'''function''' inputQuery(''Caption'', ''Prompt'', ''InitialString'') ''':''' String or nil
+
{{CodeBox|'''function''' inputQuery(''caption'', ''prompt'', ''initialstring'') ''':''' string}}
  
Displays a dialog box that prompts the user to input a string.
+
Shows a dialog where the user can input a string.
Returns the entered string, or nil if the user cancels the dialog.
+
 
 +
The function returns the entered string when the user confirms the dialog. If the user cancels the dialog, nil is returned.
  
 
===Function Parameters===
 
===Function Parameters===
Line 12: Line 13:
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|Caption
+
|caption
 
|String
 
|String
|The title of the input dialog window.
+
|The caption of the input dialog.
 
|-
 
|-
|Prompt
+
|prompt
 
|String
 
|String
|The prompt or question to display to the user.
+
|The prompt text shown to the user.
 
|-
 
|-
|InitialString
+
|initialstring
 
|String
 
|String
|The default value shown in the input field.
+
|The initial text shown in the input field.
 
|}
 
|}
 +
 +
===Returns===
 +
String or nil — The entered string, or nil if the dialog was cancelled.
  
 
===Examples===
 
===Examples===
 
<pre>
 
<pre>
-- Ask the user for their name
+
local result = inputQuery("Name", "Enter your name:", "")
local name = inputQuery("User Name", "Please enter your name:", "")
+
 
if name then
+
if result ~= nil then
   showMessage("Hello, " .. name .. "!")
+
   print("Entered name: " .. result)
 
else
 
else
   showMessage("You cancelled the input.")
+
   print("Input cancelled")
 
end
 
end
 
</pre>
 
</pre>
  
 
<pre>
 
<pre>
-- Prompt for a file name with a default value
+
local value = inputQuery("Health", "Enter new health value:", "100")
local filename = inputQuery("Save File", "Enter the file name to save:", "myfile.txt")
+
 
if filename then
+
if value ~= nil then
   print("Saving to: " .. filename)
+
   local numberValue = tonumber(value)
 +
 
 +
  if numberValue ~= nil then
 +
    print("New health value: " .. tostring(numberValue))
 +
  else
 +
    print("Invalid number")
 +
  end
 
end
 
end
 
</pre>
 
</pre>
  
 
<pre>
 
<pre>
-- Use inputQuery for a password (not masked)
+
local address = inputQuery("Address", "Enter an address or symbol:", "player.health")
local password = inputQuery("Authentication", "Enter your password:", "")
+
 
if password then
+
if address ~= nil then
   print("Password entered.")
+
   local resolvedAddress = getAddressSafe(address)
 +
 
 +
  if resolvedAddress ~= nil then
 +
    print("Resolved address: " .. string.format("%X", resolvedAddress))
 +
  else
 +
    print("Could not resolve address")
 +
  end
 
end
 
end
 
</pre>
 
</pre>
  
== See also ==
+
{{LuaSeeAlso}}
* [[showMessage]]
 
* [[Lua]]
 

Latest revision as of 00:55, 25 June 2026

⚠️ Version Notice

This function requires Cheat Engine 6.4+.

<> Lua API Reference

function inputQuery(caption, prompt, initialstring) : string

Shows a dialog where the user can input a string.

The function returns the entered string when the user confirms the dialog. If the user cancels the dialog, nil is returned.

Function Parameters[edit]

Parameter Type Description
caption String The caption of the input dialog.
prompt String The prompt text shown to the user.
initialstring String The initial text shown in the input field.

Returns[edit]

String or nil — The entered string, or nil if the dialog was cancelled.

Examples[edit]

local result = inputQuery("Name", "Enter your name:", "")

if result ~= nil then
  print("Entered name: " .. result)
else
  print("Input cancelled")
end
local value = inputQuery("Health", "Enter new health value:", "100")

if value ~= nil then
  local numberValue = tonumber(value)

  if numberValue ~= nil then
    print("New health value: " .. tostring(numberValue))
  else
    print("Invalid number")
  end
end
local address = inputQuery("Address", "Enter an address or symbol:", "player.health")

if address ~= nil then
  local resolvedAddress = getAddressSafe(address)

  if resolvedAddress ~= nil then
    print("Resolved address: " .. string.format("%X", resolvedAddress))
  else
    print("Could not resolve address")
  end
end

Main Pages

Core Lua documentation entry points

Lua
Script Engine