Battle Log with delay (Print Out List With A Delay Between Items)

Hi, 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.


  1. create a stringlist variable in your game object (or wherever you like) ,for example game.battleLog, to store all the messages.

  2. 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)
    }

  3. 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>

Log in to post a reply.

Support

Forums