Difference between revisions of "Lua:inputQuery"
Jump to navigation
Jump to search
(Created page with "Category:Lua '''function''' inputQuery(''Caption'', ''Prompt'', ''InitialString'') ''':''' String or nil Displays a dialog box that prompts the user to input a string....") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' inputQuery('' | + | {{VersionNotice|6.4+}} |
| + | {{CodeBox|'''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=== | ===Function Parameters=== | ||
| Line 11: | Line 13: | ||
!style="width: 80%;background-color:white;" align="left"|Description | !style="width: 80%;background-color:white;" align="left"|Description | ||
|- | |- | ||
| − | | | + | |caption |
|String | |String | ||
| − | |The | + | |The caption of the input dialog. |
|- | |- | ||
| − | | | + | |prompt |
|String | |String | ||
| − | |The prompt | + | |The prompt text shown to the user. |
|- | |- | ||
| − | | | + | |initialstring |
|String | |String | ||
| − | |The | + | |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> | ||
| − | + | local result = inputQuery("Name", "Enter your name:", "") | |
| − | local | + | |
| − | if | + | if result ~= nil then |
| − | + | print("Entered name: " .. result) | |
else | else | ||
| − | + | print("Input cancelled") | |
end | end | ||
</pre> | </pre> | ||
<pre> | <pre> | ||
| − | + | local value = inputQuery("Health", "Enter new health value:", "100") | |
| − | + | ||
| − | if | + | if value ~= nil then |
| − | print(" | + | 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> | ||
| − | + | local address = inputQuery("Address", "Enter an address or symbol:", "player.health") | |
| − | local | + | |
| − | if | + | if address ~= nil then |
| − | print(" | + | 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> | ||
| − | + | {{LuaSeeAlso}} | |
| − | |||
| − | |||
Latest revision as of 00:55, 25 June 2026
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