MV States that are removed after X amount of battles

Hi everyone,

I'm trying to do some basic tests with a state that is applied in the menu onto an actor. Using YEP's Buffs & States core, I'm trying to get this state to remove itself after a certain amount of battles.

This is what I have written inside the notebox:


Code:
<Custom Battle Effect>

var battleCount = battleCount || 0;

battleCount + 1;

</Custom Battle Effect>

<Custom Victory Effect>

if (battleCount > 2) {

$gameActors.actor(this._actorId).removeState(57);

}

</Custom Victory Effect>

<Custom Escape Effect>

if (battleCount > 2) {

$gameActors.actor(this._actorId).removeState(57); 

}

</Custom Escape Effect>

This doesn't work - the state remains on the actor affected by the state. Probably for obvious reasons.

1) I don't temporary created inside a state using YEP's plugin remain constant outside of battle if the state is still applied.

2) I'm very sketchy on how to remove the state from the actor affected without using an actor slot. I'm almost certain I've used "$gameActors.actor(this._actorId).removeState(57)" incorrectly here.

Anyway, thanks for any light anyone can shed on this!
About:
I'm almost certain I've used "$gameActors.actor(this._actorId).removeState(57)" incorrectly here.
---

this could help..

JavaScript:
for (var i = 1; i <= $gameActors._data.length; i++) {
    // insert stuff here
}

// this will use Var i to adress all Actors
JavaScript:
$gameActors.actor([i]).removeState(57);
// this should affect all existing Actors



Edit (edited again)
more detailed:
JavaScript:
for (var i = 1; i <= $gameActors._data.length; i++) {
    if ($gameActors.actor([i]).isStateAffected(57)) {
        $gameActors.actor([i]).removeState(57);

    }
};
//this will only use those Actors who are StateAffected

(I am not using "Party member" or "Battle member" in SRPG thats why i cant add a proper If Condition to ask if the Actor is also a BattlePartyMember.. which could be usefull aswell)
There are a few mistakes here, but the main thing is that the state will never expire because your battleCount variable is local to each notetag, i.e. in <Custom Battle Effect> it is always set to 0, then +1; in the other two tags it is always undefined. 😅

Instead, try defining it as a property on the state bearer, user, e.g. (untested):
Spoiler: Suggested notetags
Code:
<Custom Battle Effect>
user._battleCount = user._battleCount || 0;
user._battleCount += 1;
</Custom Battle Effect>

<Custom Victory Effect>
if (user._battleCount > 2) {
  user.removeState(57);
  delete user._battleCount;
}
</Custom Victory Effect>

<Custom Escape Effect>
if (user._battleCount > 2) {
  user.removeState(57);
  delete user._battleCount;
}
</Custom Escape Effect>
You might also want a <Custom Defeat Effect> tag, depending on your game's mechanics.
Hi @caethyril ,

Thanks for your solution - I just tested it and it works.

A couple of questions pertaining to this:

So, by putting a "._ "after "user" I am assigning a "property" to it, that I can assign a number that functions in a similar way to a variable?

If I use "user._battleCount" in that state, and that state has more than once instance per battle (it is active on different actors) - will these conflict with each other?
Hi @Dopan ,

Thanks for your suggestion, I can use this piece of code in other areas of my project. Cheers!
Hi @caethyril ,

Thanks for your solution - I just tested it and it works.

A couple of questions pertaining to this:

So, by putting a "._ "after "user" I am assigning a "property" to it, that I can assign a number that functions in a similar way to a variable?

If I use "user._battleCount" in that state, and that state has more than once instance per battle (it is active on different actors) - will these conflict with each other?
for ._anyNameYouWant usually means for making a private variable for an object...
It is convention to precede the name of a private variable with an underscore (_).

also it won't conflict... each actor will have individual private ._battleCount property...

hope this help.
Yeah @estriole it does! That's very handy! Thank you.
Yep, like estriole says, the underscore is optional; it's the dot that's important. 🙂

Note that if you have multiple states like this and you don't want them to share the counter, then you'll need to use a different property for each state.

Happy RPG Making~ 😂
Yeah, awesome. Thanks so much for all your help! The possibilities with adding properties are indeed vast.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/states-that-are-removed-after-x-amount-of-battles.129587/