Script now working at all

Hello everyone,

I was just trying to make a script for a custom damage formula but it is not working at all. What I made is this:

class Game_Battler < Game_BattlerBase def fire_retaliation(a, b, v)#=======================================================#What I need is something to check a state on the target#and inflict damage on the user if the state is active.#======================================================= if b.state?(26) if a.hp>v a.hp-=v #if v value is not enough to kill the user it deals normal damage else a.hp=1 #if the user HP are too low then they are set to 1 end end return v endendI just put this below "Material" in the script window and I call the script in the formula box using:

v[30]=50; a.fire_retaliation(a, b, v[30]); v[30]This is the only script I am using so it cannot be a compatibility related issue.

I feel like I am missing something obvious...

EDIT: if i write it in the formula box it works, but it needs too many characters to use it in skills with complex formulae.

r=Y; if b.state?(X) (a.hp-=r; if a.hp==0 a.add_state(1); end); end; rI ran tests with Y=50 and 0% variance.

This formula is written manually (I didn't use copy-paste) since I don't have the project with me at the moment. It is possible it contains typos.
Yeah, you're doing several things wrong.  I'll point out a few that jump out to me:

  • The proper way to reference Variable #50 in a damage formula is v[50] or $game_variables[50] but not $game_variables(50) - use brackets not parentheses.
  • The v[Y] notation won't work inside its own method in the script editor.  Since you are already passing in $game_variables[Y] as an input to the method, I think you can just change that line to a.hp-=v
  • I'm also not sure whether or not it's safe to add the Death State application into the damage formula, since the skill's effects haven't yet been applied at this point.
So I should change the script to this:

class Game_Battler < Game_BattlerBase def fire_retaliation(a, b, v) #======================================================= #What I need is something to check a state on the target #and inflict damage on the user if the state is active. #======================================================= if b.state?(X) #X is a place holder a.hp-=v if a.hp==0 a.add_state(1) #this way the user is inflicted with death state when reaching 0 HP end end endendand then call it with

v[Y]=skill_dmg; fire_retaliation(a, b, v[Y]); v[Y]but you told me that calling it into the formula box isn't safe. Is this because I eventually apply death state to the user before the skill takes place?
but you told me that calling it into the formula box isn't safe. Is this because I eventually apply death state to the user before the skill takes place?
Sorry, I left out a few words by mistake - corrected it to say that I'm not sure whether it's safe to call the Death State application at this point since the skill's effects haven't been applied yet so the system might not handle the user's premature death well.  It's something you can try out yourself, though.
Ok, now I am home and I ran few tests. What I wrote was wrong since I actually used $game_variables[30] and not $game_variables(30) so that part was correct.

I changed a.hp-=v[30] to a.hp-=v but it is still not working. No error message at all, It just deals 0 damage to both, user and target.
One other thing I just noticed: I don't think you can set a variable's value using v[Y] in your skill formula; you can only read the value with that shortcut.  Use the full $game_variables[Y] in that first segment.  v[Y] is fine in the final segment.

Besides that... not sure.  You could run a common event as part of the skill to check the value of the variable and see if that's set correctly.  You could also throw garbage like Audio.se_play('MakeItFail') inside parts of your code in the script editor - if your game throws an error, you'll know that part of the code is being hit.  This can help you detect which parts of your code are being hit properly and which aren't.
Here are my test results:

  • Skill damage is succesfully stored in variable Y using both $game_variables[Y] and v[Y]. Common event shows the correct value through text using \V[Y].
  • Code is not being hit at all...the sound didn't play, no matter where I put it.
  • Final segment of the damage formula (after calling fire_retaliation) doesn't work.
I assume there is a problem with my code/calling...but it seems I miss it ;_;

EDIT: I edited my 1st post to update the code to its actual state.
v is the entire game variables array, not a single element.


a.hp -= v does not make sense. It should be a.hp -= v[30].


You also need it to RETURN a value. That's what a damage formula is all about - getting some input, doing some calculation, returning the damage amount. Because you're not returning anything, it's 0.
That won't work.


You should put this into your damage formula:

v[30]=50; a.fire_retaliation(a, b, v[30]); v[30]Notice the a. before your custom method, that is needed there.
The damage formula is calculated in an RPG::UsableItem:😀amage instance, and NOT in the Game_Battler instance, so without that a., your formula would crash the game if not for that 'rescue 0' line at the end of the formula eval.


Whenever you try to use a custom method made in Game_Battler in your damage formula, you must use the method on a Game_Battler instance, which will be the user here, I guess.


a -= v is correct in the method, since 'v[30]' is the argument passed for the method.


And yes, there should be a number returned, but I guess that will be the variable itself (v[30])


Another thing to note, if the user dies before the skill execution, the game will crash. At least that is what happened when I last tested it. You can simply leave at least 1 HP for the user all the time, so it can't die, but still damages the user if above 1 HP.


Ohh, and on a final note, why do you use a variable in the formula? You set it right at the start of the formula, so it will always be the same. You can simply put a 50 there instead of a variable value.
Another thing to note, if the user dies before the skill execution, the game will crash. At least that is what happened when I last tested it. You can simply leave at least 1 HP for the user all the time, so it can't die, but still damages the user if above 1 HP.
I have to say that if my game chrashes at some point then at least it means my code is running somehow...but nothing. I changed my method so it doesn't kill the user.

class Game_Battler < Game_BattlerBase def fire_retaliation(a, b, v) #======================================================= #What I need is something to check a state on the target #and inflict damage on the user if the state is active. #======================================================= if b.state?(26) if a.hp>v a.hp-=v #if v value is not enough to kill the user it deals normal damage else a.hp=1 #if the user HP are too low then they are set to 1 end end return v endendI also changed my damage formula to:

v[30]=50; a.fire_retaliation(a, b, v[30]); v[30]but nothing changed: my code is not running at all.

Ohh, and on a final note, why do you use a variable in the formula? You set it right at the start of the formula, so it will always be the same. You can simply put a 50 there instead of a variable value.
Well, that is because I intend to use this in more than one single attack and using a variable requires less characters than using "a.atk*X-b.def*Y". Now it's 50 by default because I am trying to let it work, once I made it I plan to change it with the proper skill formula.

EDIT: 1st post is up to date now.

EDIT2😠Sixth: I probaly got your point right now. Do you mean I can just write

a.fire_retaliation(a, b, Y)where Y is the skill damage formula and use the default return value in the script as damage?
Yes, you only need to add that line in the damage formula (the 'a.fire_retaliation(a, b, Y)' line), where the 'Y' is the damage formula itself (or any simple numeric data).


You return the damage value at the end, so it will get a numeric data.


I just tested your custom method this way, and it works fine for me.
Well, then I really don't know where the problem is...I am still not able to run it correctly. The custom method is not being hit at all, and now I used the "a.fire_retaliation(a, b, Y)" line for the skill, using 50 as Y value.

As I said I am not using custom scripts so it should not be a compatibility related issue. Really, I am totally clueless...

EDIT: Shame on me...I forgot to save changes before testing...now it works. Thank you all for your help. This is solved for me
How do you know it's not running?


Add a:

p "something descriptive here"line in your custom method after each line.
Change that "something descriptive" to something... descriptive, so that you know on which line are you at the moment.


If you see all or some of them triggering on your console, than the damage formula is being executed, but the enemy can still neglect the damage.


Test it and see what happens.
I knew it was not running because I added a sound after each line. Anyway I just forgot to save changes, that's why it was not working. I saved them and now it works fine.

Original thread: https://forums.rpgmakerweb.com/threads/script-now-working-at-all.45719/