Having a problem with Loop Damage Calculation... (Solved)

YiKwang
24 Feb 2022, 16:21I have a Character and a Dagger with Attribute DAM_Fight
Character DAM_Fight = 3
Dagger DAM_Fight = 2
I have a turnscript to calculate how much damage the Character does:
game.pov.DAM_ThatIDo = game.pov.DAM_Fight
foreach (object, GetDirectChildren (game.pov)) {
if (HasInt (object, "DAM_Fight") and GetBoolean (object, "visible")) {
game.pov.DAM_ThatIDo = game.pov.DAM_ThatIDo + object.DAM_Fight
}
}
I have a command 'harm #object#' which is supposed to deal this DAM_ThatIDo value, based on its own and the daggers DAM_Fight combined.
if (HasAttribute(object, "LIFE_C")) {
object.LIFE_C = object.LIFE_C - game.pov.DAM_ThatIDo
msg ("You have ritually wounded " + GetDefiniteName(object) + ".")
}
But for some reason, instead of doing 5 Damage, it deals 12.
I have another Character whose DAM_Fight = 1.
However, when she wounds with a Dagger her 1+2 comes out as 10 Damage.
Any idea what is going on?

YiKwang
24 Feb 2022, 16:27I have set up a Status Panel item to show the DAM_ThatIDo value, and it shows an increase to 12 as soon as the Dagger is taken, so it is not a problem with the 'harm #object' command...
mrangel
24 Feb 2022, 17:12Are there any other scripts modifying DAM_ThatIDo
?
Are you sure that DAM_Fight
has the correct values?
Those are the first things I would check in this situation. I don't see a problem with your code.
I might also try adding "breadcrumbs"; temporarily changing the turnscript to something like:
game.pov.DAM_ThatIDo = game.pov.DAM_Fight
msg ("Calculating DAM_ThatIDo. Initial value: " + game.pov.DAM_ThatIDo)
foreach (object, GetDirectChildren (game.pov)) {
if (HasInt (object, "DAM_Fight") and GetBoolean (object, "visible")) {
game.pov.DAM_ThatIDo = game.pov.DAM_ThatIDo + object.DAM_Fight
msg (" - Adding damage for " + GetDisplayAlias(object) + " (" + object.DAM_Fight + "), total now:" + game.pov.DAM_ThatIDo)
}
}
That might seem like overkill, but trying the game with that running will give you a clear idea of exactly where in your code a problem is creeping in.
(In my code, I use JS.console.log
rather than msg
for error messages; so the debugging is hidden until you press Ctrl+Alt+J to show it… but I'm not sure whether that will work with the desktop editor)

YiKwang
24 Feb 2022, 19:37It was an incorrect DAM_Fight somewhere from testing health loss earlier xD