How to make a Combat Log with Status Panel Outputs

I am making a Combat Log which will use String Attributes to post Text with a variable component into the Status Panel.

It will work like so:

When [Current HP] is reduced,
- Set game.pov.LOG_Old = game.pov.LOG_Mid
- Set game.pov.LOG_Mid = game.pov.LOG_New
- Set game.pov.LOG_New = {"You took " + [Value of Reduction of Current HP] + "Damage."}

The trouble is, I don't want to add this process to every single event which reduces a player's current HP.

Is there a term I can use to record every single instance of game.pov.LIFE_C reduction to an Integer Attribute, which is then used to copy and paste that Integer into the [You took X Damage] String Attribute?


Maybe I can start each turn with

If LIFE_StartTurn - LIFE_C > 0
- Then
- LIFE_LastDamage = LIFE_StartTurn - LIFE_C
- game.pov.OLDLOG = game.pov.MIDLOG
- game.pov.MIDLOG = game.pov.NEWLOG
- game.pov.NEWLOG = "You took " + LIFE_LastDamage + "Damage."
LIFE_StartTurn = LIFE_C

Does this work?


I may also need to check if Satiation is 0 or lower, and if so, ignore the 1 damage lost from being hungry, but i may be fine with that 1 damage being included in the combat log's total...


I have gotten a method working as such:

if (game.pov.LIFE_StartTurn - game.pov.LIFE_C > 0) {
  game.pov.LIFE_LastDamage = game.pov.LIFE_StartTurn - game.pov.LIFE_C
  game.pov.LOG_Old = "---" + game.pov.LOG_Mid
  game.pov.LOG_Mid = "---" + game.pov.LOG_New
  game.pov.LOG_New = "---You lost " + game.pov.LIFE_LastDamage + " Health."
}
game.pov.OLDLOG = game.pov.LOG_Old
game.pov.MIDLOG = game.pov.LOG_Mid
game.pov.NEWLOG = game.pov.LOG_New
game.pov.LIFE_StartTurn = game.pov.LIFE_C

Does that look good? Or is there a much better way?


Do you want to have a log for every event that reduces the player's HP, or every turn?

I would probably make a function that reduces the player's HP and updates the messages, unless you want it to be one message per turn.

I'm not sure what the difference is between OLDLOG and LOG_Old. Is there some reason you need 2 copies of those attributes?

This method seems logical as long as you want a constant 3 lines of log; if you want more, it would probably make sense to switch to a list-based approach to avoid having three separate attributes.


OLDLOG is the Status that's in Game > Player

Log_Old is the Attribute that's listed on the playable characters themselves.


I suppose a list would be better.

Ideally, there would be the 3 last turns shown in panel, and a list of like... the last 20 - which can only be seen by use of a command like 'Com Log'


(EDIT: Fixed a silly mistake)

OLDLOG is the Status that's in Game > Player

Log_Old is the Attribute that's listed on the playable characters themselves.

Why don't you use the same attribute for both?


I suppose a list would be better.

Ideally, there would be the 3 last turns shown in panel, and a list of like... the last 20 - which can only be seen by use of a command like 'Com Log'

That's what I was thinking.
You could have a couple of functions to handle it, in case you decide you want to add stuff to the log at some point. You could have a function like…

<function name="AddLogMessage" parameters="message">
  // Create the list in case it doesn't exist
  if (not HasAttribute (game.pov, "logmessages")) {
    game.pov.logmessages = NewStringList()
  }

  // Add the new message
  list add (game.pov.logmessages, message)

  // If there's more than 20 messages saved, discard the oldest
  while (ListCount (game.pov.logmessages) > 20) {
    oldest = ListItem (game.pov.logmessages, 0)
    list remove (game.pov.logmessages, oldest)
  }

  // And make a nice list that we can put in the statusattributes, using the last 3 messages
  game.pov.LOG = "<ul>"
  for (i, ListCount (game.pov.logmessages)-3, ListCount (game.pov.logmessages)-1) {
    if (i >= 0) {
      game.pov.LOG = game.pov.LOG + "<li>" + ListItem (game.pov.logmessages, i) + "</li>"
    }
  }
  game.pov.LOG = game.pov.LOG + "</ul>"
</function>

You could call AddLogMessage from a TakeDamage function; from a turnscript; or from a game.pov.changedLIFE_C script.
Actually, I would probably use the changescript option, just because it works automatically. You could do something like:

if (IsDefined ("oldvalue")) {
  damage = this.LIFE_C - oldvalue
  if (HasString (this, "damage_message")) {
    if (not this.damage_message = "") {
      damage = "" + Abs(damage)
      AddLogMessage (Replace (this.damage_message, "!", damage))
    }
    this.damage_message = null
  }
  else {
    if (damage < 0) {
      AddLogMessage ("You healed " + (0 - damage) + "damage.")
    }
    else {
      AddLogMessage ("You took " + damage + "damage.")
    }
  }
}

That way, you can do something like:

game.pov.LIFE_C = game.pov.LIFE_C - 10

and it generates the message automatically;

or you could do:

game.pov.damage_message = "You burned yourself and took # damage."
game.pov.LIFE_C = game.pov.LIFE_C - GetRandomInt(2,4)

to get a more specific message

or for slow damage like fatigue:

game.pov.damage_message = ""
game.pov.LIFE_C = game.pov.LIFE_C - 1

stops a message from appearing for that specific damage type.


I just only ever saw someone using the LIFE / LIFE_Current / LIFE_Max method, so i've been recreating it the same way for my satiation, inventory and combat log just in case it would cause problems not to have separate things...


I just only ever saw someone using the LIFE / LIFE_Current / LIFE_Max method, so i've been recreating it the same way for my satiation, inventory and combat log just in case it would cause problems not to have separate things...

Ah, that makes sense.

The reason they're duplicated is because LIFE_Current and LIFE_Max are separate numbers, and need to be stored in separate attributes so that you can do arithmetic on them when the player takes damage… but the status attributes pane shows a single value. So you need 2 values for arithmetic, and a combined one for the status attribute.

There's no need to duplicate an attribute unless there is something different.

As you'll see in my example of how you could use a list for the status log, there's a separate variable for the status pane: because game.pov.logmessages is a list of the last 20 messages, and game.pov.LOG is a string containing the last 3 messages (status attributes cannot be lists; but there's nothing to stop you putting more than one line of text in them)

In fact, if you wanted to, you could set up the whole status pane with a single status attribute.
In the list of status attributes, you'd put a single attribute, key STATUS and value !
And then have a turnscript:

game.text_processor_this = game.pov
game.pov.STATUS = ProcessText ("Health: {this.LIFE_Current} / {this.LIFE_Max}<br/>Hunger: {this.HUNGER_Current} / {this.HUNGER_Max}<br/>{if this.POISON > 0:You are poisoned<br/>}Add more data here…")

This method would have the advantage that you can easily have attributes that disappear when not needed (like only showing the "ammo" line when the player has a gun)


Interesting... It's going to take me a few reads to get my head around all this, but I think I will work on converting the Log to a list, and maybe even using that single TEXT status display...


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

Support

Forums