Battle Log with delay (Print Out List With A Delay Between Items)
pascal.marchese
13 May 2019, 13:28Hi, here's my code for displaying the battle log (RPG style game).
pascal.marchese
13 May 2019, 13:31-
add a stringlist attribute to the game object, call it "battleLog". This will be the data storage for all the messages that will be to printed.
-
store every message of the "attacktheplayer" turnscript ("you miss...", "the enemy hits...", etc.) in the stringlist with this code:
see http://docs.textadventures.co.uk/quest/using_lists.html for reference.
add (game.battleLog, message)
- In the "attacktheplayer" turnscript (from RPG combat lib) , paste this code at the end (it shoul be at the end of every cycle of the turnscript):
foreach(entry, game.battleLog) {
request(Hide, "Command") // this is for hiding the command bar while while the timer display the logs.
EnableTimer (displayBattleLog)
}
- create a Timer (I call it "displayBattleLog"), paste this code:
<timer name="displayBattleLog">
<interval>4</interval>
<script><![CDATA[
message= StringListItem (game.battleLog, 0)
msg ("<br>" + message) // this prints the message
JS.scrollToEnd () // this scrolls the text to the bottom of the GUI
list remove (game.battleLog, message) //this removes the message from the list after it is displayed.
// Now checks if the list is empty.
// If it is, the TIMER stops the the command bar is dislayed, as normal.
if(ListCount(game.battleLog) = 0){
DisableTimer (displayBattleLog)
request(Show, "Command")
}
]]>
</script>
</timer>