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

Get help using Construct 2

Post » Mon Sep 04, 2017 10:07 pm

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 !
B
6
Posts: 38
Reputation: 337

Post » Tue Sep 05, 2017 6:47 am

try this code from Stack Overflow Environment detection: node.js or browser
Code: Select all
var isNode = false;   
if (typeof process === 'object') {
  if (typeof process.versions === 'object') {
    if (typeof process.versions.node !== 'undefined') {
      isNode = true;
    }
  }
}


myExport.capx
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Tue Sep 05, 2017 9:31 am

Semoreh wrote: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
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 480
Reputation: 7,025

Post » Tue Sep 05, 2017 9:49 am

korbaach wrote:try this code from Stack Overflow


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

OddConfection wrote: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 ! :D

Thanks a lot to you both ! :D
B
6
Posts: 38
Reputation: 337


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests