Variable & Damage Formula Help

Hello. I need a bit of help writing up a kind of absorb/heal pair of skills.

Basically what I want to accomplish is for a character to have a skill that absorbs enemy hp but doesn't use it yet. Instead, the amount of hp damage done is stored in a variable. The character can then use a special healing skill that bestows hp on an ally of the amount stored in the variable. The character can also absorb multiple times, building up the amount of stored hp, then give it all with the healing skill. The variable, of course, resets to 0 after using the healing skill

I know you can use variables in the damage formula, and I'd also found somewhere that someone posted a similar question and got an answer that seemed useful. Unfortunately, I don't remember if it was on this site, and I've been having trouble finding it again. Basically, their response was something like this (and this is what I've been using):
Code:
x = a.mat - (0.5 * b.mdf) ; y = v[2]; y += x; v[2] = y; x

Then, for the healing skill, I just put v[2]. I don't know if this is actually working, though. When I test it in game, the absorbing skill does the proper damage, but when I try to heal, it does nothing (specifically, it says the target took no damage, and a 0 pops up above their head.)

I'm not sure what I'm doing wrong, and I also don't know how to reset the healing skill to 0. I thought I could probably just call a common event in the skill effects for that, but I can't test it since in game it all comes up 0 anyways. Does it not work this way? Is there another way to do this? Should I request a plugin?

Any help would be appreciated.

-Atman
It sounds as if you made something wrong with your healing skill, because a skill set to recovery should not state "target took no damage".
Please post a screenshot of that skill
It sounds as if you made something wrong with your healing skill, because a skill set to recovery should not state "target took no damage".
Please post a screenshot of that skill
ec12d6cc65f4a13bffcca5ab599c696d.png

38c6c02191e83d79c93da7f0e87afc88.png

a6f1b4c9a6efc68ff4422458ea77b70f.jpg

Wade is the one with the absorb/infuse ability. This shot was taking after:
  • Having everyone guard
  • Wade use Bleed to steal 12 health from the enemy
  • Wade try to use Transfuse on Mark
(( Semi-related note: Leach/Transmit are just MP versions of Bleed/Transfuse. I use v[3] for them instead of v[2]. ))
Can you double-check that variable 2 contains a value before using Transfuse? (you can set up a troop event that displays the variable value in a message).
Can you double-check that variable 2 contains a value before using Transfuse? (you can set up a troop event that displays the variable value in a message).
I just tested this, and it still said the variable was 0, so it must be a problem of it not recording the damage value. I guess the damage formula must be wrong in some way? Maybe you can't record variables within the damage formula? I'm not sure what to do to fix this.
You can, I just checked it. Is the formula you posted originally EXACTLY what you have in the box?

Edit: Found your problem. When you set y to v[2], the variable is undefined, so you're setting y to undefined, adding x to an undefined variable, and then setting v[2] to an undefined variable. You need to set y to v[2] || 0 instead, then when the variable is undefined it'll use 0 for the value and it'll work properly.
You can, I just checked it. Is the formula you posted originally EXACTLY what you have in the box?

Edit: Found your problem. When you set y to v[2], the variable is undefined, so you're setting y to undefined, adding x to an undefined variable, and then setting v[2] to an undefined variable. You need to set y to v[2] || 0 instead, then when the variable is undefined it'll use 0 for the value and it'll work properly.
This worked for recording the variable, but when I tried to use Transfuse, it still came out as 'took no damage, 0.'
Weird, it worked for me with that set. Can you screenshot both your skills for me?
how exactly did you check the variable? and have you tried storing in a different variable in case something else is already configured to 2?
My test skills worked with Bleed's formula set to

"x = a.mat - (0.5 * b.mdf) ; y = v[2] || 0; y += x; v[2] = y; x"

and Transfuse set to v[2]
My test skills worked with Bleed's formula set to

"x = a.mat - (0.5 * b.mdf) ; y = v[2] || 0; y += x; v[2] = y; x"

and Transfuse set to v[2]
That's exactly what I have my skills set to as well.
how exactly did you check the variable? and have you tried storing in a different variable in case something else is already configured to 2?
I checked the variable with a troop event. After every turn, a text box will appear at the top that says VARIABLE: \V[2].
I'm pretty sure nothing else is set to variable 2, but I reassigned both skills as well as the test troop event to variable 20 just to be safe. I'll edit in the results in a second.
another question: did you test ingame or use the battletest in the database? The battletest does not have full game functionality, please test ingame.
Do you have any plugins installed?
Good news, it actually worked this time! I guess there must be something conflicting with variable 2. I'll have to go through everything and double check. Thanks for the help!
Change the formula for Bleed to this:

"x = a.mat - (0.5 * b.mdf) ; y = v[2] || 0; y += x; v[2] = y; alert(v[2]); x"

Do a test battle and tell me what the alert says.

Edit: Ah, that's good news. Hope you find the conflict.
Bad news, I've got a new problem. I've tried using Bleed twice in a row, since I wanted the health stolen to add up. After using bleed the second time, the variable came out to 0 again.

I think I sort of know how to fix it, but I don't know how to write it as code. || means 'or', yes? Instead of y = v[2] || 0, maybe that bit could be replaced by if v[20] == Null, v[20] = 0 ; y = v[20]. Idk if that's actually syntactically correct.
It's sort of or. It basically means "the operand will be v[2], or 0 if v[2] doesn't exist". It shouldn't reset to 0 when using it multiple times. I actually tested this in my own version of it, used it twice for 11 damage each time and when I used Transfuse it healed for 22.
Hmm, something unusual happened. This time when I tried to test it again, it came out to 0 again the first time.

Something is clearly going wrong somewhere else and I have no idea what it could be.

If it does matter, I am using plugins. These are the ones I'm using:

Bobstah's Battle Commands Customization
Ellye's ATB
Jeneeus Guruman's Graphics Auto-Changer
Reedo's ScanEnemy
Szyu's Crafting System
Bobstah's Enhanced Restrictions
I got it back to recording the variable for the first time, but trying to attack a second time to stack the value still brings it back to 0.

For the record, this is the troop event I have telling me the variable every turn.

88b234452601ed73ad5409f78dc2c25d.png


Simple, right?
I'm honestly not sure what's going wrong on your end, it works fine for me. Does it still give you issues if you disable the plugins?
I tested them all and no, it still resets. Though I did learn, after turning off the ATB, that it's not really a problem with the variable not being filled by the skill. Something is resetting the variable after every turn. (I know this because the ATB kinda blurred the line between turns, but after turning it off, each time the test message popped up, it still said the variable was 12 (I attacked with Blood every turn)).

Original thread: https://forums.rpgmakerweb.com/threads/variable-damage-formula-help.74978/