JavaScript questions that don't deserve their own thread

I have been trying to make some cute states for my game, and I am struggling with this one where the enemy gets healed, at the beginning of a turn, whenever they share the same state as the player. The combat of my game is based around states, so the idea here is to incentive the player towards removing the enemy's state to prevent them from being healed every turn. Anyways, this is one of the codes I tried:

JavaScript:
<Custom Turn Start Effect>
if (target.isStateAffected(22)) && ($gameParty.leader().isStateAffected(22)) {
  target.startAnimation(21);
  var value = target.mhp * 0.50
  target.gainHp(value);
}
</Custom Turn Start Effect>

Any suggestions on what I am doing wrong? Should I approach this in a different manner? Thanks much.
Try this:

JavaScript:
<Custom Turn Start Effect>
if (target.isStateAffected(22) && $gameParty.leader().isStateAffected(22)) {
  target.startAnimation(21);
  var value = Math.floor(target.mhp * 0.5);
  target.gainHp(value);
}
</Custom Turn Start Effect>
Try this:

JavaScript:
<Custom Turn Start Effect>
if (target.isStateAffected(22) && $gameParty.leader().isStateAffected(22)) {
  target.startAnimation(21);
  var value = Math.floor(target.mhp * 0.5);
  target.gainHp(value);
}
</Custom Turn Start Effect>
Thank you! That did not work initially, but once I changed Turn Start for Action End it decided to work.
That did not work initially, but once I changed Turn Start for Action End it decided to work.
Just as a note: Damage/healing popups arent automatic when a battler's hp is changed. Theres only a handful of notetags iirc that trigger them automatically. If the animation happened but not the popup, then you just needed to add an additional line to call for a popup. The healing would have happened, but there wouldnt have been a visual indication
Just as a note: Damage/healing popups arent automatic when a battler's hp is changed. Theres only a handful of notetags iirc that trigger them automatically. If the animation happened but not the popup, then you just needed to add an additional line to call for a popup. The healing would have happened, but there wouldnt have been a visual indication
You are right, thanks. It should be something like this, yes?
JavaScript:
<Custom Action End Effect>
if (target.isStateAffected(22) && $gameParty.leader().isStateAffected(22)) {
  target.startAnimation(21);
  var value = Math.floor(target.mhp * 0.5);
  target.gainHp(value);
  target.startDamagePopup();
  target.clearResult();
}
</Custom Action End Effect>
With that being said, my game features health bars for the player and enemy, so I could tell the healing was not working without the popup.
You are right, thanks. It should be something like this, yes?
yep, thats it
With that being said, my game features health bars for the player and enemy, so I could tell the healing was not working without the popup.
yeah, the comment was made in general. you have mismatched parenthesis in your first one that would have made the code not run. Slaughty's code looked fine and only "worked" when you changed the notetag so it was the first thing that came to mind
It is me again, with another state-related question. I am trying to create a state where the attacker is inflicted with "state A" if they attack an enemy that is affected by "state B". I suppose this state would work sort of like the Poison Touch passive ability from Pokémon games.

This is the code in the "state B" notetags:

JavaScript:
<Custom React Effect>
// Check if the damage dealt deals physical HP damage.
if (this.isPhysical() && this.isHpEffect() && value > 0) {
  user.addState(4);
}
</Custom React Effect>

This is the basic damage formula I use in my game. It is a bit odd, but it works fine for my purposes.

JavaScript:
if (a.isStateAffected(22)) {((a.atk + 1) - b.def) + 1} else {((a.atk + 1) - b.def)}

I tried "origin.addState(4);" as well, but it did not work. ;( I should note that I tried many variations of a state somehow applying a different state to an actor, and it just never works. I was getting really frustrated and I figured I should just accept I am idiot and ask for help again, so here I am. If I can get this working, many new state possibilities immediately open up to me.
I am trying to create a state where the attacker is inflicted with "state A" if they attack an enemy that is affected by "state B". I suppose this state would work sort of like the Poison Touch passive ability from Pokémon games.
slightly confused here. did you mean poison point?

I tried "origin.addState(4);" as well, but it did not work. ;( I should note that I tried many variations of a state somehow applying a different state to an actor, and it just never works.
Theres no syntax error in your code. your notetag should poison the attacker if they use a physical skill and deal damage to a target with that state.
just to make sure, you did give the battler the correct state, and when they got hit by another battler with a skill that did at least 1 damage it didnt cause the attacker to gain state 4?
slightly confused here. did you mean poison point?


Theres no syntax error in your code. your notetag should poison the attacker if they use a physical skill and deal damage to a target with that state.
just to make sure, you did give the battler the correct state, and when they got hit by another battler with a skill that did at least 1 damage it didnt cause the attacker to gain state 4?
Yup. Poison Point, my bad.

Also, yup. State 4 is the equivalent of a regular poison state in my game. I use the YEP_StateCategories plugin and another plugin I commissioned from Eli/Hakuen Studio that shows the current states of both the actor and enemy on the screen, at all times, which makes it really easy to know when a state is not working. Here is how state 4 looks in the database:
By the way, I wonder if the action sequence could not be interfering with the state not being applied somehow? Here is how it looks in the database:

And, lastly, here is the action sequence itself:

JavaScript:
<setup action>
display action
immortal: targets, true
if user.isActor()
    move user: point, 368, 288, 20
    jump user: 20, 20
    wait for movement
    motion thrust: user
    wait for motion
else
    move user: point, 108, 288, 20
    jump user: 20, 20
    se: Cry1, 70
    wait for movement
    motion thrust: user
    wait for motion
end
</setup action>
 
<target action>
if user.isActor()
    projectile ani 18: duration 60, start user, goal target
    se: HueSpell1, 70
    wait for projectile
    animation 19: target
    wait for animation
else
    projectile ani 18: duration 60, start user, goal target
    se: HueSpell1, 70
    wait for projectile
    animation 19: target
end
</target action>
 
<follow action>
animation 12: target
se: HueSpell39, 70
shake screen: 1, 3, 30
</follow action>
 
<finish action>
action effect

if user.isActor()
    move user: point, 388, 288, 20
    jump user: 20, 20
    wait for movement
else
    move user: point, 88, 288, 20
    jump user: 20, 20
    wait for movement
end

immortal: targets, false

if $gameTroop.members()[0].hp <= 0
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force
else if $gameParty.leader().hp <= 0:
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force
end
clear battle log
</finish action>
everything looked correct and i gave your AS and state code a shot in my main project just to be sure since it already has all the plugins needed. Theres no problem between the skill and the state effect.

Assuming your "State B" is on a battler, are you sure that your attacker isnt immune to state 4? have you tried applying a different state or doing a different effect like healing to make sure the code is running? when you press f12 to open up the console, are there any errors that show up?

you could try using a respond effect instead of a react effect too.
So, I made the basic healing spell also apply the noxious state, and it seems to work fine. The actor is not immune to it.
As for errors, as it turns out, the action sequence I posted above had two mistakes:
JavaScript:
if $gameTroop.members()[0].hp <= 0
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force
else if $gameParty.leader().hp <= 0:
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force

Should have been:

JavaScript:
if $gameTroop.members()[0].hp = 0
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force
else if $gameParty.leader().hp = 0
    shake screen: 1, 1, 30
    flash screen: 255, 0, 255, 45
    collapse, force

I will keep testing, thanks for now, Robro33!

Edit: I tried Respond over React, and the problem remained!
As for errors, as it turns out, the action sequence I posted above had two mistakes:
those arent errors and you can ignore those

you want to look at whats here
1748008102282.png



Should have been:
what you had there first was correct actually. a single equal sign is an attempt to set the value, not to check it. if you were to change the <= with anything, it would have been == or ===, but itd functionally be the same
those arent errors and you can ignore those

you want to look at whats here
View attachment 341230



what you had there first was correct actually. a single equal sign is an attempt to set the value, not to check it. if you were to change the <= with anything, it would have been == or ===, but itd functionally be the same
You are right, the actual problem was not the "<=" but the ":". I replaced the "=" with "<=" as per your suggestion!

Edit: Regarding the state, it seems like <Custom Respond Effect> and <Custom React Effect> do not work at all, regardless of state. Chances are a plugin or some setting is interfering with things ;( I think I will just move on to a different state concept, as I cannot afford to spend days trying to make one state work. Thanks again!

Edit 2: I have been testing the <Custom Whatever Effect> tags with this code:

JavaScript:
    <Custom Apply Effect>
    console.log("Howdy!");
    </Custom Apply Effect>

And, I noticed none of the <Custom Effect> that are related to targeting battlers trigger the "Howdy" in the console log. Could this be a consequence of my game only featuring one actor and one enemy per battle [kind of like in Pokémon games]? If so, at least I learned something.
And, I noticed none of the <Custom Effect> that are related to targeting battlers trigger the "Howdy" in the console log. Could this be a consequence of my game only featuring one actor and one enemy per battle [kind of like in Pokémon games]? If so, at least I learned something.

it sounds like one of your plugins after the buffs and states core overwrites the functions it uses to to work and youll have to find out which one it is. you'd have to show a screenshot of your plugin manager or start disabling them till you find out which one it is. at that point, id also suggest it to be its own thread
it sounds like one of your plugins after the buffs and states core overwrites the functions it uses to to work and youll have to find out which one it is. you'd have to show a screenshot of your plugin manager or start disabling them till you find out which one it is. at that point, id also suggest it to be its own thread
Thank you so much :3 Debugging this would be a nightmare, so I am not even going to bother. I will just pretend the broken options do not exist.
So... I have a skill that used to work just fine and now it doesn't and I'm not entirely sure why.
Basically it's a skill that does extra damage if the target has 3 stacks of a specific state.
(RPG Maker MV, using mostly Yanfly plugins)

Normal Damage Formula:

400 + a.mat * 4 - b.mdf * 2


Notetag:

<Post-Damage Eval>

if(target.getStateCounter(40) == 3) {

target.removeState(40);

target.gainHp(-1100 + a.mat * 5 - b.mdf * 2);

}

</Post-Damage Eval>
I have a question regarding Yanfly's Battle AI Core.
JavaScript:
<AI Priority>
EVAL user.tp < 3: Skill 2
EVAL user.mp < 3: Skill 2
EVAL user.hp <= user.mhp * 0.50 && !user.isStateAffected(111): Skill 128
Turn === 1: Skill 133, Highest HP%
Turn === 2: Skill 124, Highest HP%
Turn === 3: Skill 133, Highest HP%
</AI Priority>
Let us say the enemy finds themself with 2 TP in turn 2. What happens then? Does the enemy skip the turn 2 instructions [use Skill 124], opting to use Skill 2 instead, since the "EVAL user.tp <3" instructions comes first on the list? If so, what happens to the turn 2 instruction, is it gone or is it pushed to turn 3 with the turn 3 instruction being pushed to turn 4?
the enemy skip the turn 2 instructions [use Skill 124], opting to use Skill 2 instead, since the "EVAL user.tp <3" instructions comes first on the list?
yes. no line is ever skipped unless the condition is false and the first true line is always ran.

at that point it depends on the enemy's ai level though. if its at 100%, then if theyre at 2 tp on turn 2 theyll only ever use skill 2. the ai level essentially adds a random roll to each condition, so any level other than 100 adds a chance for each line to be "skipped"
Super noob question here. Does a global variable in JavaScript (with or without a value) remain even if it wasn't called or used after 20+ hours of continuous gameplay?
Does a global variable in JavaScript (with or without a value) remain even if it wasn't called or used after 20+ hours of continuous gameplay?
Time is irrelevant: if it is still in scope, it will remain in memory. No guesswork.

Garbage collection only deallocates memory once the associated values are no longer accessible. More details here:
Using the TextImage.js plugin, how do I enter a line break when calling it via script?

PluginManager.callCommand(this, "TextPicture", "set", { text: "Line 1 <LINE BREAK HERE> Line 2" });

Original thread: https://forums.rpgmakerweb.com/threads/javascript-questions-that-dont-deserve-their-own-thread.46341/