I've come to understand that the usage of <<repeat>> to constantly change the value of variables and <<replace>> them into the passage's divs is what game programmers would call a "game loop", and I've also come to understand that setInterval is not a very good way to do it.
The problem is especially apparent during a "bossfight" which has the <<repeat>> macro running for at least 10 minutes (or probably longer if the player takes longer to kill the boss): it lags the browser, and makes the setInterval timing go haywire.
I set out to test the discrepancy in timing between setInterval and the computer's clock using a simple test passage:
Actual Clock: <span id="timer">0ms</span>
setInterval Clock: <span id="timer2">0ms</span>
Timing discrepancy: <span id="disc">0ms</span>
<<set $initial_time to new Date()>>\
<<set $setinterval_time to 0>>\
<<set $setinterval_time += 100>>
<<replace "#timer">><<print new Date() - $initial_time>>ms<</replace>>
<<replace "#timer2">><<print $setinterval_time>>ms<</replace>>
<<replace "#disc">><<print new Date() - $initial_time - $setinterval_time>>ms<</replace>>
So my two questions are:
1. How do I incorporate the requestAnimationFrame() method as an alternative to <<repeat>> to "animate" my entire passage (or at least replace various elements within the passage)? Some examples of code would be nice.
2. Will exporting my game as an .exe using nw.js make my game more "playable" lag-wise? Or will nw.js run into the same timing errors that setInterval has?