Flux.Prompt classserver
Part of Active UI
Prompts: questions that the server asks a single player. Flux.Prompt:request_string
(or Player:request_string) asks them to type a text and
Flux.Prompt:request_confirmation (or Player:request_confirmation) asks them a yes or
no question. The client shows the question in a dialog window and sends the answer back,
and the server passes it to the callback of the request.
actor:request_string('ui.rename.title', 'ui.rename.message', function(target, name)
if name then
rename_item(target, item, name)
end
end, { default = item.name, max_length = 32 })
actor:request_confirmation('ui.destroy.title', 'ui.destroy.message', function(target, confirmed)
if confirmed then
destroy_item(target, item)
end
end)
Every request has an ID and can only be answered once, by the player who was asked and with the kind of answer it expects. A request that is not answered in time (5 minutes unless set otherwise) or whose player leaves is closed, and its callback is called with false, so the callback of a request that was sent always runs exactly once.
Summary
Methods
Methods
Closes a pending request: removes its dialog from the screen of the player and calls its callback with false. Serverside only.
Parameters
- id Number request ID
Returns
- Boolean true if the request was pending
Flux.Prompt:request_confirmation(target, title, message, callback, options)
server packages/active_ui/lib/sh_prompt.lua:125Asks a player a yes or no question. The callback is called with the player and true if they agreed, or false if they declined, did not answer in time or left. Serverside only.
Parameters
- target Player the player to ask; bots cannot be asked
- title String title of the dialog, text or language phrase
- message String question, text or language phrase
- callback Function called with the player and the answer (Boolean)
- options Map optional, defaults to
niloptional settings: timeout (Number seconds to wait for the answer, 300 by default, 0 to wait until the player leaves) and arguments (Map values to substitute into the title and the message)
Returns
- Number request ID, nil if the player cannot be asked
Flux.Prompt:request_string(target, title, message, callback, options)
server packages/active_ui/lib/sh_prompt.lua:110Asks a player to type a text. The callback is called with the player and the text they submitted (which may be empty), or with false if they canceled, did not answer in time or left. Serverside only.
Parameters
- target Player the player to ask; bots cannot be asked
- title String title of the dialog, text or language phrase
- message String question shown above the text field, text or language phrase
- callback Function called with the player and the answer (String, or false)
- options Map optional, defaults to
niloptional settings: default (String text the field starts with), max_length (Number longest answer in characters, 256 by default; a longer one is cut), timeout (Number seconds to wait for the answer, 300 by default, 0 to wait until the player leaves) and arguments (Map values to substitute into the title and the message)
Returns
- Number request ID, nil if the player cannot be asked