How do I detect if a game is on desktop or browser mode ?

0 favourites
  • 4 posts
From the Asset Store
20 high quality click sounds, ready to improve your game's UI instantly
  • Hi friends

    I'd like to create a save system that distinguishes whether the player is playing online on a browser (example : on itch.io) or in "desktop mode" (using the nw.exe).

    • Player is online ==> I'm saving using the LocalStorage Plugin
    • Player is on desktop-mode ==> I'm saving using the NWjs Plugin to write a simple text file.

    The goal is to protect the desktop player from losing all his save data after using Ccleaner or another tool of this kind. I find this more comforting. I just save strings of text, so nothing big.

    My question is : how do I detect if the player is playing on a web-browser or in desktop-mode ?

    I thought I could use the Browser plugin to get data on the player's session (example : Browser.Name, Brower.Platform, etc...) but it doesn't seem to work as I'd like it to. The data doesn't look useful in this case. For example, running the game in preview mode on Firefox and on NWjs, Browser.Name is always "Netscape" and Browser.Platform "Win32".

    Can someone kindly tell me where to look for ? =)

    Thanks a bunch !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • try this code from Stack Overflow Environment detection: node.js or browser

    var isNode = false;    
    if (typeof process === 'object') {
      if (typeof process.versions === 'object') {
        if (typeof process.versions.node !== 'undefined') {
          isNode = true;
        }
      }
    }[/code:7ig2pjfy]
    
    [url=https://app.box.com/s/va791uqp8826e0hb4ux3qexfeu7y6jk0]myExport.capx[/url]
  • My question is : how do I detect if the player is playing on a web-browser or in desktop-mode ?

    Maybe System->Is on platform to detect if HTML website or NW.js

  • try this code from Stack Overflow

    I'm not familiar with javascript so I can't implement this, but thanks for the suggestion !

    Maybe System->Is on platform to detect if HTML website or NW.js

    I think it works ! If I'm previewing on NW.js, the condition "Is on platform NW.js" is true, but if I'm previewing on Firefox "Is on platform HTML5 website" is the one that's true. That seems to be exactly what I was looking for !

    Thanks a lot to you both !

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