Displaying Popups #
Written by:
OmgRod
OwnerThe Popup API allows you to display Geometry Dash's native alert dialogs (FLAlertLayer) directly from your Lua scripts. When a popup opens, player movement is automatically paused until the player interacts with one of the buttons or closes the dialog.
Basic Usage #
To present a simple alert box with a single button:
lua
1-- Simple informational alert2Popup.show(3 "Welcome!", -- Title4 "Prepare yourself for the upcoming challenge.", -- Message content5 "Let's Go!" -- Button 1 text6)
You can also create interactive popups with two buttons and handle user responses via a callback function:
lua
1-- Interactive decision popup2Popup.show(3 "Choose Your Path",4 "Do you want to enter the secret area?",5 "Yes", -- Button 1 text6 "No", -- Button 2 text7 function(popup, secondButton)8 if secondButton then9 print("Player clicked No!")10 else11 print("Player clicked Yes!")12 end13 end14)
API Reference #
Popup.show(title, content, [btn1], [btn2], [callback], [doShow], [cancelledByEscape]) #
Displays a native in-game popup alert box.
Handling Callbacks #
When providing a callback function to Popup.show(), your function receives two arguments:
popup: A reference to the underlying popup layer object.secondButton(boolean): Returnsfalseif the primary button (btn1) was clicked, andtrueif the secondary button (btn2) was clicked.
lua
1Popup.show(2 "Warning",3 "Would you like to reset your progress?",4 "Keep Going",5 "Reset",6 function(popup, secondButton)7 if secondButton then8 -- Player chose "Reset" (btn2)9 state.score = 010 print("Progress reset!")11 else12 -- Player chose "Keep Going" (btn1)13 print("Continuing game...")14 end15 end16)
