W3cubDocs

/LÖVE

love.window.showMessageBox

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Displays a message box dialog above the love window. The message box contains a title, optional text, and buttons.

This function will pause all execution of the main thread until the user has clicked a button to exit the message box. Calling the function from a different thread may cause love to crash.

Function

Displays a simple message box with a single 'OK' button.

Synopsis

success = love.window.showMessageBox( title, message, type, attachtowindow )

Arguments

string title
The title of the message box.
string message
The text inside the message box.
MessageBoxType type ("info")
The type of the message box.
boolean attachtowindow (true)
Whether the message box should be attached to the love window or free-floating.

Returns

boolean success
Whether the message box was successfully displayed.

Function

Displays a message box with a customized list of buttons.

Synopsis

pressedbutton = love.window.showMessageBox( title, message, buttonlist, type, attachtowindow )

Arguments

string title
The title of the message box.
string message
The text inside the message box.
table buttonlist
A table containing a list of button names to show. The table can also contain the fields enterbutton and escapebutton, which should be the index of the default button to use when the user presses 'enter' or 'escape', respectively.
MessageBoxType type ("info")
The type of the message box.
boolean attachtowindow (true)
Whether the message box should be attached to the love window or free-floating.

Returns

number pressedbutton
The index of the button pressed by the user. May be 0 if the message box dialog was closed without pressing a button.

Examples

Display a simple message box if the user's system doesn't support shaders

local errortitle = "Shader support is required for the game to run"
local errormessage = "This system is below the minimum system requirements for the game.\
If your graphics drivers aren't up-to-date, try updating them and running the game again."
 
if not love.graphics.isSupported("shader") then
    love.window.showMessageBox(errortitle, errormessage, "error")
end

Display a message box with customized buttons

local title = "This is a title"
local message = "This is some text"
local buttons = {"OK", "No!", "Help", escapebutton = 2}
 
local pressedbutton = love.window.showMessageBox(title, message, buttons)
if pressedbutton == 1 then
    -- "OK" was pressed
elseif pressedbutton == 2 then
    -- etc.
end

See Also

© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.window.showMessageBox