How do I make two characters flash at the same time.

Sebastian2203
24 Feb 2017, 18:35

So basically, I need advice how to write javascript function withouth breaking the Quest.

The function needs to be able to flash one character for X amount of time and then another character for X amount of time.

I looked into playercore.js and I tracked how unscrambleTX and typerwiterTX works so I could try to do it myself but I know I could easily break the whole thing so I would rather ask for advice here.


Sebastian2203
25 Feb 2017, 17:11

So I to make my question more clear I will use code, also I have misspelled the names of the functions.
FXtypewriter istead of TX

So here is what I am trying to achieve in a gif : http://dwarffortresswiki.org/images/7/74/Icons.gif

As you see there are two characters flashing in one space.

Now here is what I have created in the playercore.js

    };
		$.fn.flashcharacter = function (speed) {
        this.each(function () {
            var $ele = $(this), str = $ele.text(), progress = 0;
            $ele.text('');
            var timer = setInterval(function () {
                $ele.text(str.substring(0, progress++) + ((progress & 1) && progress < str.length ? '_' : ''));
                if (progress >= str.length) setInterval(timer);
            }, speed);

Now the thing is, this is just copypasted from the fn.typewriter because I have NO idea what to change to make it flash two characters after X amount of time. Am I still too vague for anybody to help me with this?

EDIT: I also should mention that this references many other parts within the playercore.js so this sole section won´t probably explain it very well...

EDIT!!: I realized this is all a mistake because I cannot edit the playercore.js, simply because it would make it unplayable for anybody else who tries to downloand my game.


The Pixie
27 Feb 2017, 10:13

Add this to playercore.js (I added it to an attribute, and then output that inside script tags):

       flashers = [];
       flag = false;
       setInterval(function() {
         for (i = 0; i < flashers.length; i++) { 
           $(flashers[i]).css('color', flag ? 'black' : 'white');
         }
         flag = !flag;
      }, 200);
     
     
      function startFlash(elementId) {
        flashers.push (elementId);
      }

      function stopFlash(elementId) {
        index = flashers.indexOf(elementId);
        $(elementId).css('color', 'black');
        if (index > -1) {
          flashers.splice(index, 1);
        }
      }

You can then do this to start an element with the id "blink" flash:

JS.startFlash ("#blink")

And this to stop it:

JS.stopFlash ("#blink")

Sebastian2203
27 Feb 2017, 17:52

Wow, thanks! I will use it and try to disassemble it on my own to expand my knowledge.