Battle Log with delay (Print Out List With A Delay Between Items)
pascal.marchese
21 Nov 2017, 18:12Hi, here's my code for displaying the battle log (RPG style game).
I had to do some tricks because It's impossible to use the SetTimeout function inside a foreach loop.
-
create a stringlist variable in your game object (or wherever you like) ,for example game.battleLog, to store all the messages.
-
If you use the attacktheplayer turnscript (from RPG combat lib) , paste this code at the end:
foreach(entry, game.battleLog) {
request(Hide, "Command")
EnableTimer (displayBattleLog)
} -
create a Timer (I call it "displayBattleLog"), paste this code:
<timer name="displayBattleLog">
<interval>4</interval>
<script><![CDATA[
n = StringListItem (game.battleLog, 0)
msg ("<br>" + n)
JS.scrollToEnd ()
list remove (game.battleLog, n)
if(ListCount(game.battleLog) = 0){
DisableTimer (displayBattleLog)
request(Show, "Command")
}
]]>
</script>
</timer>