How do I check that game runs offline (has been added to homescreen)?

0 favourites
  • 12 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • I would like to encourage the user to add my game to their homescreen.

    So the first time the game is launched in the browser, I offer this option by running "request install".

    Once the game is added and launched offline, I need to test that game is on home screen so that install is no longer proposed.

    So how can I check that a game is running offline ?

  • 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.

  • OK, thank you. Have you tested it ? Because ChatGPT usually generates crap.

    Actually I was looking for a straight forward solution without local storage.

    Any other solution would be appreciated.

  • Laurent in the manual is mentioned that the browser is changing the display mode of the project to its app form (typically standalone display mode), if is installed. You can check that with the condition 'compare display mode' in the browser plugin, if it's in 'standalone'.

    Maybe that the easiest solution. I can't say how reliable that is you have to test it for yourself.

    It's all in here: https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/browser

  • Thank you Asmodean !

    That is a very neat approach ! I'll give it a try

    EDIT : I tried it. It is fine, Browser mode is recongnized but not Standalone nor Minimal UI...

    I'm may give it a try and check Browser/No Browser but I would have loved to be sure to know if the app is standalone.

    Any other idea ?

    something else, I also added an update system.

    After update, I prompt a button to let user reload the game but reloading the page doesn't run the updated version but previous version.

    Does user has to kill the app in order to run an update ? How can I let the user use the updated from the previous version ?

  • EDIT : I tried it. It is fine, Browser mode is recongnized but not Standalone nor Minimal UI...

    What does it shows in Browser.DisplayMode when in standalone?

    If it always shows 'Browser' then negation will have no effect.

    After update, I prompt a button to let user reload the game but reloading the page doesn't run the updated version but previous version.

    Maybe it's cached?

    If you force the App with Ctrl-R to reload does you get the new version?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What does it shows in Browser.DisplayMode when in standalone?

    If it always shows 'Browser' then negation will have no effect.

    When it's not browser it shows nothing. So I guess negation will do

    Maybe it's cached?

    If you force the App with Ctrl-R to reload does you get the new version?

    I'm working on a mobile version where Ctrl-R is not available. Only the reload action of the Browser plugin. If it is cached, is there a way to clean cache from construct ? Don't think so...

  • When it's not browser it shows nothing. So I guess negation will do

    It should.

    I'm working on a mobile version where Ctrl-R is not available. Only the reload action of the Browser plugin. If it is cached, is there a way to clean cache from construct ? Don't think so...

    On mobil I can't really help. I would make a new topic for that question otherwise it will get lost here.

  • On mobil I can't really help. I would make a new topic for that question otherwise it will get lost here.

    Thank you. I guess I'll go forward with my testing and come back to the forum to ask for this topic.

  • winkr7 - please do not use AI to generate answers. It is not allowed by the Forum & Community guidelines, because AI answers are generally garbage, and the one you provided is garbage too.

    The correct answer is that when installed, the display mode will be "standalone", so you should check for that.

  • i would love info on offline play. neeeever worked on it. working on a gatcha. offline knowledge is kinda required for idle

    thank you kindly

  • To be clear, offline support and installing the web app are actually completely separate things that work independently. It's possible to have a web export that is not installed, but works offline; it's also possible to have an installed web app that does not work offline.

    You can learn more about how projects work offline in the guide Offline games in Construct.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)