Skip to content
Will Thomas edited this page Apr 2, 2014 · 2 revisions

A collection of common dialogs packed up ready-to-use from a single function call.

##filePicker ###Usage gmlDialogs.filePicker(mode[,path[,name[,extension]]])

mode
required. Mode can be either "save" or "load" and tells whether you're wanting a save file dialog or a load file dialog; each has different conditions for it's file, e.x., "save" mode will not accept a file in a read-only directory, and open will not accept a file which does not exist.
path
optional. The directory to initially display in the file picker dialog. Default is the root directory.
name
optional. A suggested name to initially populate the file name text field.
extension
optional. If specified, an extension to require for the file. Will not open files without this extension, and will append it filenames without an extension when returning.
Returns: string or nil
Returns either the name of the file to save/load, or nil if the user hit "cancel."

###Example: This example code would show the save dialog, then save the contents of the data variable to the specified filename, if the user did not cancel.

local saveAs=gmlDialogs.filePicker("save")
if saveAs then
  local file=io:open(saveAs,"w")
  file:write(data)
  file:close()
  print("data saved to "..saveAs)
else
  print("save canceled")
end

##messageBox A simple message box, displays a message and closes when one of it's buttons is clicked. Returns the label of the clicked button. ###Usage gmlDialogs.messageBox(message[,choices])

message
required. The proverbial message of this message box. Will be word-wrapped to no more than 26 characters per line.
choices
optional. A table containing an array of strings, each string to be the label of a button on the box. This label is what is returned if that button is clicked. Buttons are done in this order, from left to right, with the right-most being the default, with focus at the start. Defaults to `{"cancel","ok"}`
Returns: string
returns the label of the clicked button.
Clone this wiki locally