Here is what chatGPT40 says:
To encourage users to add your Construct 3 game to their homescreen and ensure the "request install" option is only shown when appropriate, you can follow these steps:
### Step 1: Add the "Request Install" Option
Construct 3 has built-in support for web apps and adding to homescreens. Use the "Browser" object to request the install prompt.
1. **Add the Browser Object:**
- In your project, right-click and select "Insert New Object."
- Choose "Browser" from the list of objects.
2. **Request Install:**
- In your Event Sheet, create an event that triggers when the game is first launched (e.g., `On start of layout`).
- Add an action: `Browser -> Request install`.
### Step 2: Detect if the Game is Running Offline
You can check if the game is running offline by using the "Browser" object’s condition `Is online`.
1. **Create a Global Variable:**
- Create a global variable (e.g., `isInstalled`) to track whether the game has been added to the homescreen.
2. **Check Online Status:**
- In your Event Sheet, create an event to check if the game is online.
- Add a condition: `Browser -> Is online`.
3. **Set Up Logic to Show/Hide Install Prompt:**
- If the game is online and not installed (`isInstalled` is false), show the install prompt.
- If the game is offline, set the `isInstalled` variable to true, assuming it has been added to the homescreen.
### Example Event Sheet Setup
```plaintext
Global Variables:
isInstalled (Boolean) = false
On start of layout:
Browser -> Request install
Browser -> Is online:
Trigger once:
If isInstalled is false:
Browser -> Request install
Browser -> Is offline:
Set isInstalled to true
```
### Step 3: Add Logic for Persistent State
To ensure the `isInstalled` variable retains its value across sessions, you might need to use local storage.
1. **Add the Local Storage Object:**
- Insert the "Local Storage" object into your project.
2. **Save and Load the Install Status:**
- When the game detects it is offline, save the `isInstalled` state to local storage.
- On start of the layout, load the `isInstalled` state from local storage.
### Example Local Storage Implementation
```plaintext
On start of layout:
Local Storage -> Check item "isInstalled"
Local Storage -> On item "isInstalled" exists:
Local Storage -> Get item "isInstalled"
Local Storage -> On item "isInstalled" missing:
Set isInstalled to false
Browser -> Request install
Local Storage -> On item "isInstalled" get:
Set isInstalled to Local Storage.ItemValue
Browser -> Is offline:
Set isInstalled to true
Local Storage -> Set item "isInstalled" to true
```
### Summary
By setting up these events, your game will:
1. Prompt the user to add it to their homescreen on the first launch.
2. Detect if it’s running offline and assume it’s been installed.
3. Use local storage to remember the install state across sessions, ensuring the install prompt is not shown again once the game has been added to the homescreen.
This approach provides a smooth user experience and encourages users to install your game while respecting their previous actions.