.slice and setTimeout to make a working ticker bar?

I have $gameVariable.value(1) displayed on my HUD, continuously updating. I am trying to create a system to display a string one letter at a time, much like the default text system but that can be updated while other things are happening.

It feels like it should be fairly simple but the code I have just causes the game to freeze on start. Help would be hugely appreciated.

Code:
var testString = "I'll never be hungry again."

var ticker = function() {

    var i = 0;
    do {
        setTimeout(function(){
            $gameVariables.setValue(1, testString.slice(0,i));
            i++;
        }, 100);
    }while (i <= testString.length)
        
};
take a look here
http://pixijs.download/dev/docs/PIXI.ticker.Ticker.html
It's not working because of how the variables are scoped. setTimeout and setInterval add functions to the event loop which means it's executed in the global context. So what's happening is the i variable which is incrementing is not the one you expect and your 'while' loop is executing forever.
If all you're using the i variable is iteration, why not a 'for' loop?

Even if you fix that, it still isn't going to work as you expect. The way you have it, it would send 27 function calls to the event loop and all 27 will begin execution exactly 100ms later. So your text will appear all at once.

It could be useful for you to read some documentation on setInterval and setTimeout to understand better how it works.

Original thread: https://forums.rpgmakerweb.com/threads/slice-and-settimeout-to-make-a-working-ticker-bar.94875/