Quest - Online SAVE Command (FIX)

I am posting this again because I've had a few people message me concerning this recently.


When saving a game online, the text will not be saved when using the SAVE command. (Everything works fine when you click the 'Save' button, though.)

This is a fix. When entering SAVE, this will check for the online player, then it will call the appropriate save function. This way, the text will be saved either way. (I got the OnlineCheck code from Pixie.)

  <function name="OnlineCheck" type="boolean"><![CDATA[
    s = " " + 0.1
    return (Instr(s, ",") > 0)
  ]]></function>
<command name="savecmd">
  <pattern>save</pattern>
  <script><![CDATA[
    if(OnlineCheck()){
      JS.saveGame()
    }
    else{
      request (RequestSave, "")
    }
  ]]></script>
</command>

will this be corrected in the next Quest version?


I had no idea this was an issue.

I am slightly worried about OnlineCheck; it is basically a hack, being based on bizarre behaviour in the web player that ideally would get corrected. I am sure there must be some other way to check, perhaps some JavaScript variable we could set in the web player and see if it exists. These things tend to be hard to test.


1. There is a built-in JS boolean variable in playerweb.js called webPlayer.

2. When clicking the save button online, it runs this JS:

saveGame();
afterSave();

Using that stuff, this does the job:

  <command name="save_cmd">
    <pattern>save</pattern>
    <script>
      game.notarealturn = true
      game.suppressturnscripts = true
      JS.eval ("if(webPlayer){saveGame(); afterSave();scrollToEnd();}else{ASLEvent('DoLocalSave', '');};")
    </script>
  </command>
  <function name="DoLocalSave" parameters="bool">
    request (RequestSave, "")
  </function>

Tester:

http://textadventures.co.uk/games/view/dwifgxmjakwcsk2zotidiw/online-saves


Whoops. I was mistaken. The webPlayer variable is declared in WebPlayer/player.js on line 2, not in playerweb.js.


What exactly is'webplayer'? Do you want to check if you have an online connection or if the mobile player is used? I have written two Javascript functions for it:

function testOnline() {
    var check = false;
	if( window.location.hostname != "local") {
		check=true;
	} 
	ASLEvent("checkOnline", check);
	return false;
}

function testMobile() {
    var check = false;
    var elem = document.getElementById('tabButton');
    if (elem!=null){
      check=true;
    }
    ASLEvent("checkMobile", check); 
    return false;
}

What exactly is'webplayer'?

webPlayer is an existing JS boolean variable in WebPlayer/player.js on line 2.

If the player is playing online, webPlayer will be set to "True", so the testOnline() function could just be:function testOnline(){return webPlayer;}.

I once set up a JS function which set a game attribute the first time SAVE was entered. This only ran once. After that, the scripts checked game.isonline instead of using JS to check webPlayer. This was error-prone, because sometimes things go wrong during the initial check (remember that we ARE talking about the web player, which is known to be quite error-prone). I found that using JS to check for webPlayer before every save is the safest way to do this. (I've been adding this to my games for about 5 months.)


Recently, Dcoder was having problems with doubles online. Apparently, the . is changed to a , when a double is converted to a string via concatenation. Upon seeing this, Pixie (jokingly) pointed out that we could do this:

  <function name="OnlineCheck" type="boolean"><![CDATA[
    s = " " + 0.1
    return (Instr(s, ",") > 0)
  ]]></function>

I laughed at the time, but I've been using this instead of running a JS function (which calls an ASLEvent that calls a Save request) ever since, and it always works correctly.


if the mobile player is used?

That testMobile() function looks a lot like this:
http://textadventures.co.uk/forum/samples/topic/bzmjia3zd0qtrmaw72tkxq/check-if-player-is-on-a-mobile-device

A pull request which includes the JS function isMobilePlayer() was recently merged. So, Quest 5.8 will have this feature already, unless something is changed before it is released.

I honestly think testMobile() may be superior to isMobilePlayer(), by the way. (Both work when tested, though.)


...but it doesn't matter if the game is being played in the mobile browser as far as entering SAVE is concerned. It only matters if the player is using the desktop player or the web player.

If the player is online, WebPlayer/player.js will be loaded and webPlayer will be True.


This code works (you can play the test game to which I linked to test it out), but I bet the code posted by Pertex works just as well.

It doesn't matter to me which code is used, as long as something is done to fix the issue. [INSERT SMILEY FACE HERE]


The code in this post is not so good.

See my next post.


OLD CODE

Of course, the best solution would probably be adding this to WebPlayer/Mobile/playermobile.js:

var mobilePlayer = true;

Then we could just do:

if (webPlayer){
  console.log("The player is playing online!");
  if (mobilePlayer){
    console.log("...and the player is on a mobile device, so no panes or location bar!");
  }
}else{
  console.log("The player is using the desktop version of Quest.  (Thank goodness!)");
}

The webPlayer variable is already in the code.

Here's a test game to test that out:

http://textadventures.co.uk/games/view/wvlh6nzhq0ubvwdjtgnnua/mobile-play-sound

<!--Saved by Quest 5.7.6615.29455-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Check for webPlayer">
    <gameid>f88391ff-8cb4-4515-b525-c90dce715193</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <menufont>Georgia, serif</menufont>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[{command: webPlayer check}<br/><br/><hr/><br/><code><br/>JS.eval ("webPlayer ? alert('You are playing online.') : alert('You are using the desktop player.');")<br/></code><br/><hr/>]]></description>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <command name="webplayer_check_cmd">
    <pattern>webplayer;web player;player;web;webplayer check;web player check;test;testing</pattern>
    <script>
      JS.eval ("webPlayer ? alert('You are playing online.') : alert('You are using the desktop player.');")
    </script>
  </command>
</asl>

UPDATE

I don't know if I've said this already (and I'm too lazy to ready through my posts), but the best thing to do would be adding var mobilePlayer = true;to WebPlayer/Mobile/mobileplayer.js

The most efficient way I've found beyond that change to the source code is described below.


I added code (stolen from Pertex) to check for the mobile player.

This will return true if the mobile player setup is loaded (typeof($('#tabButton').html()) != 'undefined')

I think this might be the most efficient version of a function to check for the mobile player's display settings being set up (unless var mobilePlayer = true; were simply added to WebPlayer/Mobile/mobileplayer.js):

 function mobilePlayerCheck(){
    return (typeof($('#tabButton').html()) != 'undefined');
};

I updated the test game:
http://textadventures.co.uk/games/view/dobiqko6m0enqgfs8zxefw/check-for-webplayer

It works correctly on all of my devices.

<!--Saved by Quest 5.7.6615.29455-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Check for webPlayer">
    <gameid>f88391ff-8cb4-4515-b525-c90dce715193</gameid>
    <version>3.0</version>
    <firstpublished>2018</firstpublished>
    <menufont>Georgia, serif</menufont>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[{command: webPlayer check}<br/><br/><hr/><code>JS.eval ("webPlayer ? addTextAndScroll('You are playing online.') : addTextAndScroll('You are using the desktop player.');")</code><hr/><br/><br/>{command: mobilePlayer check}<br/><br/><hr/><code>JS.eval ("if(typeof(mobilePlayerCheck)=='undefined'){ function mobilePlayerCheck(){return (typeof($('#tabButton').html()) != 'undefined');}}")<br/>JS.eval ("mobilePlayerCheck() ? addTextAndScroll('You are using a mobile device.') : addTextAndScroll('You are not using a mobile device.');")</code><hr/>]]></description>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <command name="webplayer_check_cmd">
    <pattern>webplayer;web player;player;web;webplayer check;web player check;test;testing</pattern>
    <script>
      JS.eval ("webPlayer ? addTextAndScroll('You are playing online.') : addTextAndScroll('You are using the desktop player.');")
    </script>
  </command>
  <command name="mobile_player_check">
    <pattern>mobile player;mobile check;mobileplayer;mobileplayer check;testing;test</pattern>
    <script>
      JS.eval ("if(typeof(mobilePlayerCheck)=='undefined'){ function mobilePlayerCheck(){return (typeof($('#tabButton').html()) != 'undefined');}}")
      JS.eval ("mobilePlayerCheck() ? addTextAndScroll('You are using a mobile device.') : addTextAndScroll('You are not using a mobile device.');")
    </script>
  </command>
</asl>


The only catch would be a player who opened the game in a mobile browser, opened the settings, then switched to desktop view.

The mobile browser rules would still apply, which would effect sounds the text formatting (and who knows what else).

I've tried to do this on my tablet before, and it makes it very difficult to play a game. Every time you send a command, it zooms in on the new text output and you have to zoom back out to see the entire page again.

I think this would be acceptable. If someone is switching to desktop view in a mobile browser, they're asking for trouble anyway!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums