Skip to content

PopupInput

Anthony Headley edited this page May 28, 2024 · 6 revisions

PopupInput() : int

Signature:

PopupInput(
   {title:str,
   caller:handle,
   items:table:{
      {'str'|'int'|'lua'|'handle', name, type-dependent}...},
   selectedValue:str,
   x:int,
   y:int,
   target:handle,
   render_options:{left_icon,number,right_icon},
   useTopLeft:bool,
   properties:{prop:value}
}): int:index, string:value

Brief:

Displays a Radio or Option list the user can select an item from and returns what item the user selected.

This seems to allow several types of options including strings, numbers and maybe, LUA or other display handles. more information is needed.

Parameters:

Name Description Optional
string:title Title of the dialog box ✔ (string or nil)
object:displayhandel the main display_value
table: value Can be a table value of strings for each option or a table of tables in the format of {"int" | "str" | "lua" | "handle", name , type dependant}. This second method needs more details
string: selectedvalue String of selected value
integer: x X position of Left side of the Dialog
integer: y Y position of Top of the dialog Dialog
target:handle Unknown
render_options:table? {left_icon,number,right_icon} - Needs more info
useTopLeft:bool Affects the origin of the dialog, not exactly sure how
properties:table? {prop:value} - Needs more info

Returns (multi-return):

choiceIndex, choiceText

nil: both the choiceIndex and choiceText will return nil if the user cancels the selection.

int: zero-based selected value string: Text of the selected item

error documentation says it returns a string:value

...

Examples:

Option 1:

local function Main(display_handle)
   local popupData = {} -- this table will contain all the options for the PopupInput
   popupData["title"] = "Select your type of pizza"
   popupData["caller"] = display_handle
   popupData["items"] = {"Pineapple", "Pepperoni", "Mushroom"}
   popupData["selectedValue"] = "Pepperoni"
   popupData["x"] = 100
   popupData["x"] = 100
   popupData["target"] = nil  -- Needs more info
   popupData["render_options"] = {left_icon = "arrow_right.tga", number = 0, right_icon = "arrow_left"} -- Not sure how to use, Needs more info
   popupData["useTopLeft"] = false -- changes dialog origin, but not sure how
   popupData["properties"] = nil -- not sure of valid properties.
 
   local choiceIndex, choiceText = PopupInput(popupData)  --calls the popup with our options

   if index == nil then  -- check the results (returns int or nil)
      ErrPrintf("Nothing on your pizza Wierd!")
   else
      Printf("result: " .. choiceIndex .. " is type: " .. type(choiceIndex) .. " and value " .. choiceText ) -- result: 0 is type number
   end
end
return Main

Option 2:

local function Main(display_handle)
   local r = PopupInput({title="Pick the Even Number", caller=display_handle, items={1,2,3}})
   if r == 1 then -- this checks for the zero based second item
      Printf("Yup")
   else
      Printf("Nope")
   end
end
return Main
Clone this wiki locally