JS function to find the last divOutputAlign in a saved game [SOLVED]

K.V.

UPDATE: Altering the clearMenu function is the simple and proper fix for this. Just so you know before you read all of my 'notes' I posted while finding a fix.


NOTE: I found a dirty way to make it work here, but you can scroll on down to mrangel's posts for the solution.

http://textadventures.co.uk/forum/quest/topic/ik0dbblaq0o5fdqq7nuwia/js-function-to-find-the-last-divoutputalign-in-a-saved-game-solved#14cb0c29-3383-4c85-ae2b-611a9ae81558


Hello,

I've gone crazy trying to solve this one.

When play begins, if you leave it where it displays the title and author, you have divOutputAlign1 through divOutputAlign5.

That's what I have, anyway.

EDIT: This is sort of a math/JS problem, so if yours is different, we can just shift the numbers around. ACTUALLY a problem with the clearScreen function. (Thanks, mrangel.)


Maybe we just need a function to search for the text divOutputAlign, then assign the highest number to a variable. Then, we'll feed that variable to setDivCount.

A JS function which finds what the highest numbered divOutputAlign in a saved game is what I'm really after here.


When you take a turn, two instances of divOutputAlign are created.

One appears to be whitespace (between turns), the second is this:

>jump
You jump, but nothing happens.


If that was your first command, you would now have divOutputAlign6 and divOutputAlign7.

divOutputAlign6 is an empty element, and divOutputAlign7 contains the HTML code for the outputted text.

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572695-46c5499a-b071-11e7-8616-4379fde712af.png)

Now, for those of you who never use ClearScreen, you have no worries concerning any of this.

The rest of us have a chance of running into problems when people load saved games.

...unless the player is using the web player, in which case the screen will be cleared when play begins. (This is actually a good thing for us screen-clearers.)


These next few screenshots aren't any fun. They only show what happens when the screen is NOT cleared.

I start the game. I jump. Then I save, putting me at divOutputAlign9.

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572732-0413005a-b072-11e7-9983-a1c5f3b1da58.png)

Now I load the saved game and Z, giving me divOutputAlign10, which is good:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572754-75ecf212-b072-11e7-8305-2e42befcd56e.png)

Now, let's do the same thing, but clear the screen before we save.

Wait...

First I'll show you what happens when we clear the screen. It just deletes all previous instances of divOutputAlign (and the numbering system will remain intact). This, I believe, is so Quest doesn't have to deal with any <output> which won't be displayed when a saved game is loaded.

I'm starting the game, jumping, clearing the screen (I made it a command), then saving.

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572780-45a1782a-b073-11e7-92a3-d57e2309152b.png)

Now, I load the saved game:

When play begins, I am at divOutputAlign12, just as I should be:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572825-3af0e180-b074-11e7-8d1a-bf442ff77897.png)

This is the data Quest saved to load the text:

  <output>
    <html><![CDATA[<div id="divOutputAlign10" style="text-align: left" class="section3"></div><div id="divOutputAlign11" style="text-align: left" class=""></div><div id="divOutputAlign12" style="text-align: left" class="section4"><span style="font-family:Georgia, serif;color:Black;font-size:12pt;"></span><br><span style="font-family:Georgia, serif;color:Black;font-size:12pt;">&gt; save</span><br></div>]]></html>
  </output>

When I enter a command, the divOutputAlign numbering system is broken. Everything from here on out is divOutputAlignNaN, which breaks ShowMenu.

This was discussed here:

http://textadventures.co.uk/forum/quest/topic/6j-wzgnus0urepk6bksura/what-can-break-displaying-menus#cebf0fcd-9060-4e6d-a714-03e33549d05e

That does fix the problem with ShowMenu, but it seems to cause other problems.


I opened my saved game and added my 'fix' to this game:

    <inituserinterface type="script">
	  JS.getDivCount ()
    </inituserinterface>

Now my first move after loading the saved game is labeled divOutputAlign1!

Ruh-roh, Raggy!!!

What will happen once divOutputAlign rolls back up to an ID that's in the game already, you ask?

Well... The text in the FIRST instance of that ID will be displayed, of course!!!

The funny thing is that it replaced divOutputAlign10 and divOutputAlign11 with the NEW text, but it seems to get 'stuck' at the current one, which is divOutputAlign12. So, it prints the new divOutputAlign11 above the old divOutputAlign12:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31572933-7b2e9e0c-b076-11e7-8565-c9afcbdae794.png)

If you are changing rooms when this happens, it can be quite confusing.

I'm sure either:

  • JS can be used to find the strings containing divOutputAlign in the saved game file, then set the highest number as the new divOutputAlign, hence fixing everything.

OR

  • We can set up an attribute in Quest that multiplies game.currentturnoutputsection by something to make sure the latest divOutputAlign has a number higher than the last one.

Like I say, this has been driving me crazy.

I've been working on it for about 24 hours now. (With little forum breaks in between, of course!)

22 of those hours were spent trying to find what I'd done in one of my scripts that kept my room description from changing after loading a saved game. Then, I noticed it didn't matter if I switched rooms. It did it on the same turn number after loading the game every time.

That's when I remembered the ShowMenu thing and got to the point I am now at: right where I started.


Here are the JS functions from playercore.js that are related to this:

code ``` function createNewDiv(alignment) { var classes = _outputSections.join(" "); setDivCount(getDivCount() + 1); $("
", { id: "divOutputAlign" + getDivCount(), style: "text-align: " + alignment, "class": classes }).appendTo("#divOutput"); setCurrentDiv("#divOutputAlign" + getDivCount()); }

var _currentDiv = null;

function getCurrentDiv() {
if (_currentDiv) return _currentDiv;

var divId = $("#outputData").attr("data-currentdiv");
if (divId) {
    _currentDiv = $(divId);
    return _currentDiv;
}

return null;

}

function setCurrentDiv(div) {
_currentDiv = $(div);
$("#outputData").attr("data-currentdiv", div);
}

var _divCount = -1;

function getDivCount() {
if (_divCount == -1) {
_divCount = parseInt($("#outputData").attr("data-divcount"));
}
return _divCount;
}

function setDivCount(count) {
_divCount = count;
$("#outputData").attr("data-divcount", _divCount);
}

</details>

K.V.

So, I went with option B, and it seems to work.

I added this to Before entering room for the first time on the first room:

  game.inituserinterface => {
    JS.setDivCount (ToInt(game.lastoutputbeforesave) * 3)
  }

I added this to the save script:

game.lastoutputbeforesave = game.currentturnoutputsection
xlist = Split(game.lastoutputbeforesave, "n")
game.lastoutputbeforesave = ListItem(xlist,1)
//===================================
// Everything before this was added 
// by KV to fix the loaded saved game 
// divOutputAlign issue.
// ===================================
//
request (RequestSave, "")

FIXED.

...but it's dirty.

Anyone have a clean solution? Perhaps some way to alter a JS function and do it properly?


The value is stored as an attribute of an HTML element on the page, so you should be able to get it like this (in JS):

var divId = $("#outputData").attr("data-currentdiv");

That said, is the issue that this is wrong?


$("div[id^=divOutputAlign]").last()


Or a more complete example; haven't tested yet, but I think this should work:

setDivCount($("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]+1);

(Does setDivCount contain the ID of the last div, or of the next one to be inserted? If the former you don't need the +1; but may be worth doing +0 anyway to force it to cast a string to an int)


Or you could change the way the is stored so that it gets saved correctly:

setDivCount = function(count) {
  _divCount = count;
    $('<input type="hidden">').attr('name': 'divcount[]').attr('value',_divCount).attr('class','divCountField').appendTo("#outputData");
}

getDivCount = function() {
  return $(".divCountField").last().attr('value');
}

(maybe a little less efficient, though)

@Pixie:

The value is stored as an attribute of an HTML element on the page, so you should be able to get it like this (in JS):

As far as I can tell, the save game code stores the contents of $("#outputData") … not the outputData div itself (and so the attribute isn't restored when loading a saved game)


K.V.

First, I created this JS function:

setDivCount = function(count) {
  _divCount = count;
    $('<input type="hidden">').attr('name': 'divcount[]').attr('value',_divCount).attr('class','divCountField').appendTo("#outputData");
}

getDivCount = function() {
  return $(".divCountField").last().attr('value');
}

I get this result:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31575725-b1287302-b0b2-11e7-8573-4195248d2315.png)

setDivCount($("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]+1);

That threw an error, so I ended up with this in my inituserinterface:

game.inituserinterface => {
  JS.setDivCount($("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]+1);)
}

I get this:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31575798-1854edac-b0b4-11e7-9d14-a3cfa2c24069.png)

Now, notice how it moves the output around when I get back to a divAlignOutput that already exists:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31575838-d94e7bae-b0b4-11e7-9076-9edb05b22585.png)

For now, I've got it set up just a little differently than what I put in the last post.

From what I've looked at, the divOutputAlign number is the number of the corresponding section times 2 plus 4.

So, this is what I've got right now:

Save script (same as above)

game.lastoutputbeforesave = game.currentturnoutputsection
xlist = Split(game.lastoutputbeforesave, "n")
game.lastoutputbeforesave = ListItem(xlist,1)
//===================================
// Everything before this was added 
// by KV to fix the loaded saved game 
// divOutputAlign issue.
// ===================================
//
request (RequestSave, "")

inituserinterface

game.inituserinterface => {
  JS.setDivCount ((ToInt(game.lastoutputbeforesave) * 2) + 4)
}

Which sets it correctly (in this case):

screenshot ![image](https://user-images.githubusercontent.com/30656341/31575925-604b348e-b0b6-11e7-8a72-93388245b90e.png)

I can't see why mrangel's code doesn't work.

Of course, I can't see why Pixie's doesn't either...

>The value is stored as an attribute of an HTML element on the page, so you should be able to get it like this (in JS):
>
>var divId = $("#outputData").attr("data-currentdiv");
>That said, is the issue that this is wrong?

I wish I could provide an intelligent answer to that, Pix.

If I leave everything as it is by default, all of the divOutputAlign`` IDs end inNaN```.

If I call getDivCount in inituserinterface, It starts them back over from 1, and crazy things happen on screen when a new one overlaps with an old one. Sometimes the old element with no text aligns with the new element with text, and everything seem to print to the screen correctly. But when there are two elements with the same ID, I think the browser prints the first one it finds to the screen, rearranging all the rest in order of the ID name.

I'll set up an example, but it makes the player think he hasn't changed rooms when it happens while exiting a room.

This is actually what brought my attention to this fully. Pertex ran into the room description thing a couple of days ago while lending a helping hand.


I've been trying to find a JS function that finds every instance of divOutputAlign in a document. Then, I think it could work from the position of that string to pick out the last occurrence, remove the searched string from the string, convert that to an integer, and add 1 to that.

That looks an awful lot like what mrangel's code should be doing to me.

Everyone who has posted code so far is much more knowledgeable in JS than I am, though. I just started getting into it.

...and I may not be plugging mrangel's code into the right place. (I think I am, though. I showed all of my 'work' above.)


If I call getDivCount in inituserinterface, It starts them back over from 1, and crazy things happen on screen when a new one overlaps with an old one.

I have seen that myself. It happens if you try to print anything from inituserinterfacepresumably because at that point the div count has not been set.


K.V.

I have seen that myself. It happens if you try to print anything from inituserinterface presumably because at that point the div count has not been set.

Hmm...

I'm not trying to print anything from inituserinterface in this one, though.

Wait... I bet you mean the <output> from the saved game hasn't loaded that HTML at that point. It's usually at the very end of my game, so Quest would read it until last; correct?

If that's true, something similar to the script I added to the save function may be the best way to keep up with it, only calling the JS function posted by mrangel and saving the variable to a game attribute before saving. Then using that game attribute pretty much like I did here.


I don't think my method of multiplying the number of the last output section by 2 then adding 4 will always work for everyone, but I'm not sure.

I'm using the first altered save script I posted, where I just multiply the number of the last output section by 3.

There are gaps in the divOutputAlign numbering scheme, but nothing overlaps, so it solved the problem in this particular game. I guess it doesn't matter if they're not sequential, as long as Quest can put them in order. (The divOutputAlign elements, I mean.)


I'm going to try to call mrangel's function on save instead of from inituserinterface. I don't fully understand the whole thing, but I can tell what each little thing does and slowly piece them all together in my old mind. It looked like it should work to me, and the results not changing any makes sense now. The HTML elements didn't exist yet when I called that function from inituserinterface.

It'll be about an hour before I get back to it, though.

I must go deliver a fresh can of Whoop-ass to my 19-year-old first.


I'm trying to understand what happens when a saved game is restored; but I'm not that good with jQuery, and have no experience at all with the language for all the "hard-coded" stuff.

Can someone with the full version of Quest tell me what order these steps occur in?

  • Loading playercore.js
  • Restoring the saved outputData content
  • Running the UI initialisation script
  • Running any JS files included in the game

@KV

setDivCount($("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]+1);
That threw an error, so I ended up with this in my inituserinterface:

Can you share the error? My suspicion would be that it's an order of execution issue (this would fail if the previous output contents hasn't yet been restored).
Actually, that would also give an error the first time it's run if you're not loading a saved game. Maybe needs to check if $("div[id^=divOutputAlign]") actually matches anything first, and setDivCount(1) otherwise.


K.V.

I think it's like Pixie said, and #divOutput doesn't exist when inituserinterface runs.

It only did it at the beginning of a new game. So I set the initialization script to set the initialization script up with that function.

That way, the function will run every time the game loads EXCEPT for the very first time, which was the only time it threw that error (which I will go recreate in one second).


We'll need Pix to verify this, but I'm fairly certain it's:

  • playercore.js
  • inituserinterface
  • saved output data

The JS files included only run when a function is called (I think).

If you add a function with the same name as a default function, it acts just like a function you copy from Quest: it overrides it.

I've got Pixie's new ClearMenu function as a stand-alone JS file in the game that will be released soon. Quest calls it instead of the one in playercore.js all on its own.


https://github.com/ThePix/quest/wiki/UI-Part-05:-Where-and-When-To-Do-Stuff


K.V.

Loading a new game with the function in inituserinterface:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578085-d61811ea-b0df-11e7-897f-56d93f6f0a6a.png)

Error running script: Error compiling expression '$("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]+1': SyntaxError: Unexpected character: $Line: 1, Column: 1Unexpected token "/"; expected one of ")"Line: 1, Column: 73

Loading the save (no error):

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578105-1c5095f6-b0e0-11e7-847c-6add2032fcc6.png)

...but...

Before I enter any commands (everything is in order):

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578119-613fb570-b0e0-11e7-852f-f7a634b56807.png)

Now I'm only entering JUMP repeatedly:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578141-b0abceb4-b0e0-11e7-97a5-927df147069a.png)

See how there are duplicates showing in the tools menu?

See how the order my turns were printed in changed around (I didn't JUMP until after loading the save)?


mrangel,

Your script is setting it up as 0, I believe. It was a returning a string.

If run this with the default function, it returns NaN, which I believe is JavaScript-ese for Not a Number.

I'm home now, and I'm wanting to set it up so that your function runs on game save. I want it to set a game attribute for the value it returns, then call that in inituserinterface on every load except for the first time you open the game.


I do not know is the simple answer (ETA: this is in response to the post a couple up now!). It is buried somewhere in the C# which I do not have access to at the moment.

The page KV linked to is what I found the hard way trying to get Deeper to work, and is a little out of date now. The next version will have JS.addScript which will allow you to add scripts (and CSS) by-passing the whole divCount system, to solve some of the issues, but not what you guys are looking at.

As far as I can tell, the save game code stores the contents of $("#outputData") … not the outputData div itself (and so the attribute isn't restored when loading a saved game)

It saves the contents of divOutput, which has outputData as its first element, followed by divOutputAlign1, 2, 3... so it potentially has access to the original valve. I would guess that was why it was put into the HTML, rather than just stored as a JS variable.


K.V.

From the Quest 5 directory in Windows, I can't find thesaveGamefor the desktop player (playercore.js is calling saveGame() on that line):

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578283-d1c2985a-b0e3-11e7-99b3-a7e66ccd9294.png)

...but here it is in desktopplayer.js (from the source code -- it isn't in the desktopplayer.js in the main Quest directory after an install):

function doSave() {
    UIEvent("Save", $("#divOutput").html());
}

It's a JS function in the online player, though:

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578297-12bfa1d6-b0e4-11e7-88a4-6d7810e24e1a.png)

See the last two functions here:

https://github.com/textadventures/quest/blob/master/WebPlayer/player.js


And here's a link to playercore.js:

https://gist.github.com/KVonGit/f0bf86fa9c094e0b71b2f768f6123087#file-playercore-js


And desktopplayer.js:

https://gist.github.com/KVonGit/9f355677e1386e43a61ca554f2fb847e#file-desktopplayer-js


This may help, too:

https://github.com/textadventures/quest/blob/528ead7b1cc2b3be3c2f8c427d0b67074ba76d12/Prototypes/jsrunner/index.html


I wasn't paying attention. I thought it was setting attributes on the container.

It saves the contents of divOutput, which has outputData as its first element

clearScreen() deletes the entire contents of divOutput. If you clear the screen immediately before saving, does that mean that outputData isn't recreated and is missing from the saved output? That would explain the original bug that prompted this thread.


Yeah, that looks about right.
So if I'm following this right, in clearScreen() you probably want to create a new outputData.

$("#divOutput").html("");
could be changed to either:
$("#divOutput").html('<div id="outputData" style="display: none;" />');
or
$("#outputData").appendTo($("#divOutput").empty());
(depending if you want to clearing the screen to reset any other attributes that outputData has)

and the subsequent calls to setCurrentDiv and setDivCount will give it some attributes


K.V.

this is in response to the post a couple up now

Sorry about that, Pix!

I don't know what all mrangel can access without Windows.

By the way, when I say "going/driving me crazy", it's not in an angry way. I just really want to figure it out.


Here is the example game I've been experimenting with:

http://textadventures.co.uk/games/view/q1qahgyn90kw2i2c2dhhta/testing-saves

It can't be tested online, though. A loaded saved game starts with a cleared screen, so there are no existing divOutputAlign elements until a turn is taken.


screenshot ![image](https://user-images.githubusercontent.com/30656341/31578805-209282b0-b0ee-11e7-9c6c-ca270e522a07.png)

After 4 JUMPs and a NORTH:


screenshot ![image](https://user-images.githubusercontent.com/30656341/31578649-08c331d2-b0eb-11e7-8607-f177f78985f4.png)

When using desktop player:

If your last two or three turns didn't output lengthy prose, you can see it switching the order of your commands around if you pay attention, but it just looks like you get stuck in the room if the last command or two filled up your screen (and you can't see all the commands since you loaded the saved game).

AND you can't interact with anything in the room description on the screen, because you're not really in that room. (This is what Pertex encountered, which made me seriously look at this.)

It's just a glitch concerning the outputted text.

I put an object in room3 which can't be taken.

The Places and Objects pane DOES show the children of the room in which you actually are, and you can interact with said objects. (The compass works correctly as well.)

The status bar displays your location properly, too.

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578953-685476be-b0f1-11e7-91b7-cf869c0829b9.png)

screenshot ![image](https://user-images.githubusercontent.com/30656341/31578979-ac73eb72-b0f1-11e7-9b93-b658ad16fc53.png)

KV: I think we may have been typing at the same time. I'm not sure as I can't test it, but I think I found a much, much simpler solution. Just modify clearScreen() so that it doesn't move outputData outside of divOutput, preventing it from being saved. (see my posts ↑ just before your last one)

I can look at the code, as I have Quest "installed" under WINE; I just can't run it.
grepping through the *.js files looking for the functions was my first reaction.


K.V.

Sorry, mrangel. It apparently took me about 40 minutes to type that last while experimenting in between.

...but it's fine in the desktop player after clearing the screen and immediately saving.

I clear the screen and saved. I was at divOutputAlign12.

I load the save game.

When play begins, I am at divOutputAlign12, just as I should be:

screenshot

image


The web player loads a saved game with a cleared screen no matter what.

All of the games I've played online, including games that never clear the screen during play, start with a cleared screen.

I'm 99% sure Pixie mentioned this being fixed in the next release, but he may have been referring to the status bar...

EDIT: I'm 100% sure Pixie mentioned the status bar thing being fixed in the next release. (Ha-ha! Whoops!)

http://textadventures.co.uk/forum/quest/topic/qdwn7teux0im1uaryij1jw/while-a-game-is-being-tested#a3fd3237-fe4b-4604-b0e0-39fe93774513)

Either way, the web player just makes you spend an extra turn if can't remember where you are and whatnot, that's not too big of a thing. The player has just loaded a saved game at that point, so they're less likely to consider it a bug in the game and stop playing.


I'm 99% sure Pixie mentioned this being fixed in the next release, but he may have been referring to the status bar...

It was the status bar!


K.V.

I think I'd have it if I could figure out how to set game.lastDivBeforeSave to $("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0] with JS.

The + 1 that used to be on the end of that code added a "1" to the end of the string.

In this case, it returned "7", so the output was "71".

"7" was the correct answer, though. That is, in fact, the number of the last divOutputAlign.

If I can set that "7" (returned by mrangel's JS function) as a string (or an integer) on game.lastDivBeforeSave, I can put this in inituserinterface and I bet it will solve this:

game.inituserinterface => {
    JS.setDivCount (ToInt(game.lastDivBeforeSave))
  }

KV: You shouldn't need that. That line of code is a really clunky workaround.

I'm about 95% sure that if you override clearScreen with a version that doesn't delete outputData, Quest will be able to save and restore CurrentDiv and DivCount in the way it was intended to, and none of these more complex solutions would be necessary.

If you include this in your game:

function clearScreen() {
    $("#divOutput").css("min-height", 0);
    $("#outputData").appendTo($("#divOutput").empty());
    createNewDiv("left");
    beginningOfCurrentTurnScrollPosition = 0;
    setTimeout(function () {
        $("html,body").scrollTop(0);
    }, 100);
}

and don't call SetDivCount(), can you find any problematic behaviour?


K.V.

mrangel,

We were posting at the same time on two threads, and I missed that. (I just happened to be messing with ClearScreen at the same time as you, I guess.)

I will do it that way next.

But I did figure out how to make it work correctly my way just now.

There are quite a few clunky bits, but I'm posting the code here before I mess with it, just for posterity.

(I shall return with the results after altering ClearScreen.)

Click here to see a fix which involves much too much work.
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="testing saves">
    <gameid>61ad98f8-d95b-4200-b15a-73db2248901b</gameid>
    <version>1.3</version>
    <firstpublished>2017</firstpublished>
    <feature_advancedscripts />
    <multiplecommands />
    <inituserinterface type="script"><![CDATA[
      game.inituserinterface => {
        SetTimeout (1) {
          JS.setDivCount (toInt(game.lastDivOnSave))
        }
      }
    ]]></inituserinterface>
  </game>
  <command name="save">
    <pattern type="string">^save$</pattern>
    <script>
      request (RequestSave, "")
      JS.getDivCountKV ()
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[This is the first room.<br/><br/>Enter the next room. Then save the game, load it, see what messes up!]]></description>
    <firstenter type="script">
    </firstenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="north" to="room2">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <description type="script"><![CDATA[
      msg ("Welcome to room2!<br/><br/>The screen has been cleared.<br/><br/>{command:Save} the game, load it, then take the following steps:<br/><br/><br/><pre><code><br/><br/> LOOK 4 times<br/><br/>GO N (or S)<br/><br/></code></pre><br/><br/><hr/><br/>See what messes up?<br/>")
    ]]></description>
    <enter type="script">
    </enter>
    <beforeenter type="script">
      ClearScreen
    </beforeenter>
    <exit alias="south" to="room">
      <inherit name="southdirection" />
    </exit>
    <exit alias="north" to="room3">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="room3">
    <inherit name="editor_room" />
    <description><![CDATA[It's nice in the third room.<br/>]]></description>
    <object name="thing">
      <inherit name="editor_object" />
      <scenery type="boolean">false</scenery>
      <takemsg>This thing is just to show you what's happening here.  You can't take it.</takemsg>
      <alias>thing in room 3</alias>
    </object>
    <exit alias="south" to="room2">
      <inherit name="southdirection" />
    </exit>
  </object>
  <command name="clear">
    <pattern>c;clear</pattern>
    <script>
      request (ClearScreen, "")
    </script>
  </command>
  <function name="setKV" parameters="div">
    set (game, "lastDivOnSave", div)
  </function>
  <javascript src="divToAtt.js" />
</asl>

divToAtt.js

function getDivCountKV() {
      var divToAtt = parseInt($("#divOutput").find("div[id^=divOutputAlign]").last().attr("id").match(/[0-9]+/)[0]);
      ASLEvent("setKV", divToAtt)
      addText(divToAtt)
}

Pix,

Sorry about putting those words in your mouth in the earlier post. (I went back and edited that part to avoid confusing anyone.)


Anyone who's reading all of this,

Sorry.

We all go a little mad sometimes, right?


K.V.

If you include this in your game:

function clearScreen() {
   $("#divOutput").css("min-height", 0);
   $("#outputData").appendTo($("#divOutput").empty());
   createNewDiv("left");
   beginningOfCurrentTurnScrollPosition = 0;
   setTimeout(function () {
       $("html,body").scrollTop(0);
   }, 100);
}

and don't call SetDivCount(), can you find any problematic behaviour?


mrangel,

I really wish I'd have slowed down and read that post!

It stripped out everything I added and simply created that JS function.

It works perfectly.

Thank you!

screenshot

image



Also

The web player loads a saved game with a cleared screen no matter what.

Either way, the web player just makes you spend an extra turn if can't remember where you are and whatnot, that's not too big of a thing.

I guess that could be an issue if your game counts turns. Thanks for pointing it out :)
So if I'm writing something where turn count is relevant, I should include some code in the UI init script to send a recap to the client if it hasn't been done by the system.


K.V.

I subtract 2 turns on saving after checking whether the online player is being used.

This is my JS script to check it (the webPlayer function exists by default):

var bool = false;
function playerCheck() {
  if (webPlayer) {
    //addText("<br/>[Game running in Online player.]");
    bool = true;
    ASLEvent("setOnline", bool);
    //gameFinished();
  }
  else {
    //addText("<br/>[Game running in Desktop player.]");
    bool = false;
    ASLEvent("setOnline", bool);
  }
}

Your idea sounds like a pretty good thing to add, too.


wouldn't/couldn't subtracting/adjusting the turns possibly screw up the game (depending on its design, or even possibly regardless of the person's game design) ??

(I was thinking the same thing too of just subtracting 1... not 2 though --- which I now understand why its 2 and not 1 lol, but then I'm like, no... that can potentially mess up the game, so never posted priorly about jsut subtracting/adjusting the turns)


K.V.

Nah, HK. It just adjusts the turn count. If you have a clock, and depending how it's set up, it might make time go backwards too, but that's all I can theorize I at the moment.

And I didn't realize I didn't have game.notarealturn = true set on save until this came up. So I figure it's just as easy to decrease it the turn count by 2.

Now you've got me wondering about it...

I'll be back.


what about this save/load stuff/JS/etc stuff that has me seeing stars... lol (I tried, I tried, to read and understand this thread... but... NOPE... don't understand it at all, lol)

would messing with the turns, mess up the (future) saves and loads ??? maybe some funky stuff might happen ?? saving the same content twice, or whatever, loading at an unexpected spot, etc etc etc


K.V.

The turn count is just an attribute we have to set up. It isn't built-in. Quest doesn't care about it at all.

I had it subtracting 2 on save, but only when playing online, where you start a saved game with nothing on your screen but a command prompt. You'll probably have to look, which takes 1 turn you wouldn't have wasted, and saving was counting as a turn because I hadn't set the script on it to discount it.


I did go test it out, though, HK. There were no problems, even when I saved on the first turn and the turn count was negative when I loaded the saved game.

Here's the little game I made to test it:

code
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="turns">
    <gameid>c1aae2ba-8a34-4cd9-a4a7-8aa79fdc5efa</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <turns type="int">0</turns>
    <notarealturn type="boolean">false</notarealturn>
    <statusattributes type="stringdictionary">
      <item>
        <key>turns</key>
        <value></value>
      </item>
    </statusattributes>
  </game>
  <command name="save">
    <pattern type="string">^save$</pattern>
    <script>
      game.notarealturn = true
      request (RequestSave, "")
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript name="turnCount">
    <enabled />
    <script>
      if (not game.notarealturn) {
        game.turns = game.turns + 1
      }
      game.notarealturn = false
    </script>
  </turnscript>
  <javascript src="kvAddons.js" />
</asl>

that's really cool !!!! (you're really developing/discovering/fixing/solving a lot of really cool stuff and/or issues we've been having, keep it up KV... and then at some point, be patient and try to teach/help me with learning all of this stuff, lol)

does any of this stuff help with the scrolling controls that another thread was asking about (do you now know how to get/control it to scroll to the top, as that's what that other thread's OP user was asking about)


K.V.

does any of this stuff help with the scrolling controls that another thread was asking about (do you now know how to get/control it to scroll to the top, as that's what that other thread's OP user was asking about)

I think so...

I think this might take you to the top of the HTML's <body> element:

EDITED (THIS WORKS)

SetTimeout (2) {
  JS.eval ("$('html, body').stop().animate({scrollTop: 0}, 'slow');")
}

I'll test it and come right back.


UPDATE

If you use that in a script, you need a SetTimeout that is NO LESS THAN 2 SECONDS. Otherwise it immediately scrolls back down to the text input field (you can barely see it happen sometimes).

EDITED

    <enter type="script">
    SetTimeout (2) {
      JS.eval ("$('html, body').stop().animate({scrollTop: 0}, 'slow');")
    }
    </enter>

This works.

Example game code

EDITED

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Scroll to Top">
    <gameid>c1aae2ba-8a34-4cd9-a4a7-8aa79fdc5efa</gameid>
    <version>1.1</version>
    <firstpublished>2017</firstpublished>
    <turns type="int">0</turns>
    <notarealturn type="boolean">false</notarealturn>
    <statusattributes type="stringdictionary">
      <item>
        <key>turns</key>
        <value></value>
      </item>
    </statusattributes>
    <commandpane />
    <feature_advancedscripts />
    <inituserinterface type="script">
      JS.setCommands ("Scroll to top")
    </inituserinterface>
    <description><![CDATA[Example game.<br/><br/><br/>-----------------------------------------------------------<br/>SetTimeout (2) {<br/>  JS.eval ("$('html, body').stop().animate({scrollTop: 0}, 'slow');")<br/>}<br/>-----------------------------------------------------------]]></description>
  </game>
  <command name="save">
    <pattern type="string">^save$</pattern>
    <script>
      game.notarealturn = true
      request (RequestSave, "")
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <description><![CDATA[All work and no play makes Jack a dull boy.  All work and no play makes Jack a dull boy.  All work and no play makes Jack a dull boy.  <br/><br/><br/>All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy.   <br/><br/>   All work and no play makes Jack a dull boy.  <br/><br/>        All work and no play makes Jack a dull boy.  <br/><br/>All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy.  <br/>All work and no play makes Jack a dull boy.   <br/><br/>   All work and no play makes Jack a dull boy.  <br/><br/>        All work and no play makes Jack a dull boy.  <br/><br/>All work and no play makes Jack a dull boy.  <br/><br/><br/><br/>]]></description>
    <enter type="script">
      SetTimeout (2) {
        JS.eval ("$('html, body').stop().animate({scrollTop: 0}, 'slow');")
      }
    </enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript name="turnCount">
    <enabled />
    <script>
      if (not game.notarealturn) {
        game.turns = game.turns + 1
      }
      game.notarealturn = false
    </script>
  </turnscript>
  <command>
    <pattern>top;scroll up;scroll top;scroll to top</pattern>
    <script>
      SetTimeout (2) {
        JS.eval ("$('html, body').stop().animate({scrollTop: 0}, 'slow');")
      }
      game.notarealturn = true
    </script>
  </command>
  <javascript src="kvAddons.js" />
</asl>

http://textadventures.co.uk/games/view/oc4uvldffuo98j0yjajavw/scroll-to-top


It now works online (in Chrome, Firefox, Internet Explorer, Edge, and Samsung's stock browser on my Galaxy S6).


K.V.

you're really developing/discovering/fixing/solving a lot of really cool stuff and/or issues we've been having,

I'm just standing on other people's shoulders...

Especially Pixie and mrangel (which is who solved my issue here).

If it weren't for those two, I'd be clueless about any of this CSS and JS stuff.

at some point, be patient and try to teach/help me with learning all of this stuff

Any time, HK!


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

Support

Forums