Make a simple and efficient game guardian menu template script with 3 functions and UI hiding implementation, if user selected one of the options in the menu it should hide script & game guardian UI and it should be shown again if the user interacted with game guardian icon after that.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a simple and efficient Game Guardian menu template script with 3 functions and UI hiding implementation. This script uses the gg.showUI and gg.hideUI functions to show and hide the Game Guardian UI, respectively. The gg.showUI function takes a boolean parameter to determine whether to show or hide the UI.
lua
-- Define a table to store the menu options
local menu_options = {
"Option 1",
"Option 2",
"Option 3"
}
-- Define a function to show the menu
local function show_menu()
local choice = gg.choice(menu_options, nil, "Select an option")
if choice == nil then
-- User cancelled the menu
return
end
-- Call the corresponding function based on the user's choice
if choice == 1 then
option_1()
elseif choice == 2 then
option_2()
else
option_3()
end
end
-- Define the three menu option functions
local function option_1()
gg.alert("You selected Option 1")
hide_ui()
end
local function option_2()
gg.alert("You selected Option 2")
hide_ui()
end
local function option_3()
gg.alert("You selected Option 3")
hide_ui()
end
-- Define a function to hide the Game Guardian UI
local function hide_ui()
gg.showUI(false)
end
-- Define a function to show the Game Guardian UI
local function show_ui()
gg.showUI(true)
end
-- Set up a callback function to show the UI when the user interacts with the Game Guardian icon
gg.setVisible(false)
gg.setRootOutsideCallback(show_ui)
-- Show the menu initially
show_menu()
Here's how the script works:
The menu_options table stores the three menu options.
The show_menu function displays the menu using gg.choice and calls the corresponding function based on the user's choice.
The option_1, option_2, and option_3 functions are the three menu option functions. Each one displays an alert and calls the hide_ui function to hide the Game Guardian UI.
The hide_ui function calls gg.showUI(false) to hide the Game Guardian UI.
The show_ui function calls gg.showUI(true) to show the Game Guardian UI.
The gg.setVisible(false) line hides the Game Guardian icon initially.
The gg.setRootOutsideCallback(show_ui) line sets up a callback function to show the UI when the user interacts with the Game Guardian icon.
The show_menu function is called initially to display the menu.
When the user selects an option from the menu, the corresponding function is called, which displays an alert and hides the Game Guardian UI. To show the UI again, the user needs to interact with the Game Guardian icon, which triggers the show_ui callback function and shows the UI.
Note: This script assumes that you have the Game Guardian API available in your environment. If not, you may need to adjust the code accordingly.