GD Resources logo

Displaying Popups #

OmgRod avatar
Written by:
OmgRod
Owner

The 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 alert
2Popup.show(
3 "Welcome!", -- Title
4 "Prepare yourself for the upcoming challenge.", -- Message content
5 "Let's Go!" -- Button 1 text
6)

You can also create interactive popups with two buttons and handle user responses via a callback function:

lua
1-- Interactive decision popup
2Popup.show(
3 "Choose Your Path",
4 "Do you want to enter the secret area?",
5 "Yes", -- Button 1 text
6 "No", -- Button 2 text
7 function(popup, secondButton)
8 if secondButton then
9 print("Player clicked No!")
10 else
11 print("Player clicked Yes!")
12 end
13 end
14)

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:

  1. popup: A reference to the underlying popup layer object.
  2. secondButton (boolean): Returns false if the primary button (btn1) was clicked, and true if 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 then
8 -- Player chose "Reset" (btn2)
9 state.score = 0
10 print("Progress reset!")
11 else
12 -- Player chose "Keep Going" (btn1)
13 print("Continuing game...")
14 end
15 end
16)