Getting Timers to Update the UI

lordpalandus
14 Oct 2017, 02:23

Hi,

When I've used timers in my game, they will properly produce text on the screen, but will not update the UI. This is an issue because it forces the player to scroll the screen down and the game will not take user inputs until they scroll the screen down.

So, is there a way to force Quest to scroll the screen down when a timer activates?


K.V.
14 Oct 2017, 02:26

Hello,

Try JS.scrollToEnd().


hegemonkhan
14 Oct 2017, 02:34

is there other JS scrolingl controls?

as there's another thread that doesn't like the scrolling to the bottom... maybe there's a: 'JS.scrollToStart ()' or 'JS.scrollToTop ()', though this still might not be desirable if it even exists...


K.V.
14 Oct 2017, 02:39

Not that I know of.

Here's the JS function from playercore.js:

function scrollToEnd() {
    var scrollTo = _animateScroll ? beginningOfCurrentTurnScrollPosition - 50 - $("#gamePanelSpacer").height() : $(document).height();
    var currentScrollTop = Math.max($("body").scrollTop(), $("html").scrollTop());
    if (scrollTo > currentScrollTop) {
        var maxScrollTop = $(document).height() - $(window).height();
        if (scrollTo > maxScrollTop) scrollTo = maxScrollTop;
        var distance = scrollTo - currentScrollTop;
        var duration = _animateScroll ? distance / 0.4 : 1;
        // Added by The Pixie on behalf of alexandretorres
        if (duration>2000) duration=2000;
        $("body,html").stop().animate({ scrollTop: scrollTo }, duration, "easeInOutCubic");
    }
    $("#txtCommand").focus();
    // Added by The Pixie; this is a fall back, as the above seems not to work on some browsers
    // In fact it may be the all the rest of this can deleted
    $('html,body').animate({ scrollTop: document.body.scrollHeight }, 'fast');
}

I use JS.scrollToEnd like it's going out of style in Text Adventures with no issues (that I know of).


hegemonkhan
14 Oct 2017, 02:53

@ KV:

hmm... from the looks of it there's a way to do it... though it's a bit confusing for me... as it deals with the various windows'/frames' position coordinates and math stuff.. etc... I've done some graphics work... but still am a bit confused by it...


you might be able to make more sense of it, KV, as I'm still not used to all of these command-symbols and JS/html stuff...


if you're wondering about this line:

var duration = _animateScroll ? distance / 0.4 : 1;

it's a ternary (3 condition) operator, basically a quick/shortcut (programmers are lazy) way of doing an 'if/else' Script:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator (ternary operators: 'xxx ? xxx : xxx', are in some other languages too, like C++. It's not limited to JS only)

condition ? condition : condition
condition (if true then do) condition (else then do) condition // conceptually what the symbols translate to

binary (2 condition) operators: and, or, xor, nand, nor, xnor, etc

condition and condition
condition or condition
etc etc etc

unary (1 condition) operators: not

not condition


lordpalandus
15 Oct 2017, 23:32

Thanks! Worked like a charm, and saved my ambience system from being scrapped. Thanks a ton!