RPG Battle Log (display battle messages with delay between lines)

Hi, here's my code for displaying the battle log (RPG style game: https://textadventures.co.uk/forum/samples/topic/5976/rpg-style-combat-library-2-0) .
Also, check forum topic "Print Out List With A Delay Between Items" for reference.
I had to do some tricks because It's impossible to use the SetTimeout function inside a foreach loop.
The concept is simple:
You must add a stringlist attribute to the game object, I call it "battleLog".
Every turn the "attacktheplayer" turnscript runs, (I am referring to the code of the RPG Combat library) you must add the message ("You hit ...", "you miss...", "the enemy hits you..." etc. ) in this stringlist.
After every turn, there's a timer (you must create it) that reads and prints every line from the battleLog stringlist.
Once this is done, (at the end of every turn) EMPTY the stringlist, ready for the next turn.


SO, THIS IS IT:

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

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

So, does this run the entire battle, win or loose? Or it is turned based?
Does it display:
You hit it.
(pause)
It missed you.
(pause)
You hit it.
(pause)
It hit you.
(pause)
You hit it, and killed it.
(battle over.)


It is turn based, this runs every turn. It you have a party with multiple attacks this could be very useful.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums