xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
Hi there. I have a few passive states added to items that are doing a few annoying things, and it seems like it would be fixed if I could just move the "end of turn" flag around.

For example, there's robes that give a character +Magic Damage for the first three turns of battle. In the state's notes:
<Passive Condition Cases>
Battle Turns > 0
Battle Turns < 3
</Passive Condition Cases>

This means that the state doesn't become active until all moves are selected, and turn 1 begins. Once the final character makes an action selection, the state appears and is active. This by itself is fine, however the issue is that the effect appears to stay active into the turn where it's supposed to end, because the "end of turn" flag is set for after everyone's made their action.

This gives the impression that you'll have that state once the turn begins, but as soon as the actions start, that counts as the last turn ending, and the state disappears. You might have made your action based on the false information of having that state going into the next turn. I'm not sure if I explained it properly, but if that made any sense at all, what would a proper solution be?

TLDR Passive states that should be gone still appear when making action selections, because the end of turn flag doesn't occur until the actions are all selected.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
A solution that doesn't alter the rest of the game would to have it go off of the regeneration phase, which happens at the end of all actions before action selection for the next turn begins.

So you could put a Turn 0 troop event that sets a variable (we'll say 37) to 1. Then in your passive state you put:
Code:
<Passive Condition: Variable 37 Below 4>

<Custom Regenerate Effect>
$gameVariables._data[37]++;
</Custom Regenerate Effect>

That should cause the state to switch off at the end of battle turn 3.

If for some reason that doesn't work, it's possible to modify where increaseTurn() is called, but that could have greater/unexpected effects on the game overall.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
A solution that doesn't alter the rest of the game would to have it go off of the regeneration phase, which happens at the end of all actions before action selection for the next turn begins.

So you could put a Turn 0 troop event that sets a variable (we'll say 37) to 1. Then in your passive state you put:
Code:
<Passive Condition: Variable 37 Below 4>

<Custom Regenerate Effect>
$gameVariables._data[37]++;
</Custom Regenerate Effect>

That should cause the state to switch off at the end of battle turn 3.

If for some reason that doesn't work, it's possible to modify where increaseTurn() is called, but that could have greater/unexpected effects on the game overall.
This is a really clever, and cool idea that I'm probably not smart enough to do properly. It doesn't even fully compute in my head too clearly because I don't have that much experience messing with actual code like this.

I'll definitely give it a shot though. Thank you.

Edit: I tried everything as you wrote out, and it does work, to my shock! I went ahead and added the BATTLETURNS variable set to 0 at the start of each troop battle. You're a wizard.

But there is a few other problems with this I'm running into.


1. I'd prefer it if the icon wasn't active in the menu screen, since you know... it's supposed to only be active for the first turns "in battle", not outside of battle. I can't really think of how to make it go away besides making the variable a crazyhigh number like 200 between battles somehow. Not sure how to do that, since if I use an autorun event on the map it just locks me in place forever.

2. If I use two equipments with the same script of:

Code:
<Passive Condition: Variable 37 Below 4>

<Custom Regenerate Effect>
$gameVariables._data[37]++;
</Custom Regenerate Effect>

won't that add two counters to the variable every turn, thus messing up the timing of both?
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
1. I'd prefer it if the icon wasn't active in the menu screen, since you know... it's supposed to only be active for the first turns "in battle", not outside of battle. I can't really think of how to make it go away besides making the variable a crazyhigh number like 200 between battles somehow.
I don't understand why it would have to be a "crazy high number like 200" - your state is only active while variable 37 is below 4, so why wouldn't you simply make it 4? You could put an autorun on your maps or use a plugin to run a common event at the end of every battle.

Not sure how to do that, since if I use an autorun event on the map it just locks me in place forever.
In addition to getting this figured out, you may want to revisit some eventing tutorials as this is considered pretty basic functionality.

The two common ways to stop an autorun/parallel event are:
1 - Turn on a self-switch and make another event page with that switch as a condition. This is not good for your case because the self-switch is permanent unless switched off again with a command. But it should be a basic way you know to not make it lock you in place forever.

2 - Use the Erase Event event command. This applies while you are on that instance of the map, so every time it loads again the event comes back. This is exactly what you want.

2. If I use two equipments with the same script...won't that add two counters to the variable every turn, thus messing up the timing of both?
Yes. If you're going to have multiple pieces of equipment giving this same state, then we'd alter the state and its tags this way:

Code:
<Custom Passive Condition>
condition=user.turnCount && user.turnCount<4;
</Custom Passive Condition>

<Custom Battle Effect>
user.turnCount=1;
</Custom Battle Effect>

<Custom Regenerate Effect>
user.turnCount++;
</Custom Regenerate Effect>

<Custom Victory Effect>
delete user.turnCount;
</Custom Victory Effect>

<Custom Escape Effect>
delete user.turnCount;
</Custom Escape Effect>

These bits of code will work entirely by themselves. No need for any troop events or map autorun events.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
This is a really clever, and cool idea that I'm probably not smart enough to do properly. It doesn't even fully compute in my head too clearly because I don't have that much experience messing with actual code like this.

I'll definitely give it a shot though. Thank you.

Edit: I tried everything as you wrote out, and it does work, to my shock! I went ahead and added the BATTLETURNS variable set to 0 at the start of each troop battle. You're a wizard.

But there is a few other problems with this I'm running into.


1. I'd prefer it if the icon wasn't active in the menu screen, since you know... it's supposed to only be active for the first turns "in battle", not outside of battle. I can't really think of how to make it go away besides making the variable a crazyhigh number like 200 between battles somehow. Not sure how to do that, since if I use an autorun event on the map it just locks me in place forever.

2. If I use two equipments with the same script of:

Code:
<Passive Condition: Variable 37 Below 4>

<Custom Regenerate Effect>
$gameVariables._data[37]++;
</Custom Regenerate Effect>

won't that add two counters to the variable every turn, thus messing up the timing of both?
I really appreciate you helping me out with this. I'm not at all good with custom coding tasks like this and barely understand how it all works, but I got like 80 hours of what's essentially a VN already done haha. There's just simply some things I've missed along the way, especially that "erase event" thing. I didn't know it erased the event, but came back after. Good to know.

So this is becoming a bit of a tangled web for me, unfortunately. There's a few confusing aspects to it. I used that long line of code in the state's notes, but it just never appeared in battle. Did you write it with that variable in mind? Or is "turncount" a synonym for that variable you had me set up earlier? Sorry I'm so brainless with this.

I have the armor which gives the "first 3 turns buff" state set to

<Passive State: 523>
So that should apply it. And it does when I simply have the state's notes set to
<Passive Condition Cases>
Battle Turns > 0
Battle Turns < 3
</Passive Condition Cases>
But again, this is the initial setup that makes it so the state icon appears and disappears at the weird turn changes. At least it functions this way, though.

Again I really appreciate the help.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
I used that long line of code in the state's notes, but it just never appeared in battle.
That's because I'm a dummy and a passive state that isn't on won't run its Battle Effect.

So change your passive state notetags to this instead:
Code:
<Custom Passive Condition>
condition=!user.turnCount || user.turnCount<4;
</Custom Passive Condition>

<Custom Regenerate Effect>
user.turnCount=user.turnCount || 1;
user.turnCount++;
</Custom Regenerate Effect>

<Custom Victory Effect>
delete user.turnCount;
</Custom Victory Effect>

<Custom Escape Effect>
delete user.turnCount;
</Custom Escape Effect>
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
That's because I'm a dummy and a passive state that isn't on won't run its Battle Effect.

So change your passive state notetags to this instead:
Code:
<Custom Passive Condition>
condition=!user.turnCount || user.turnCount<4;
</Custom Passive Condition>

<Custom Regenerate Effect>
user.turnCount=user.turnCount || 1;
user.turnCount++;
</Custom Regenerate Effect>

<Custom Victory Effect>
delete user.turnCount;
</Custom Victory Effect>

<Custom Escape Effect>
delete user.turnCount;
</Custom Escape Effect>
Really feels like it's my fault, not yours, cause it's still just not activating in battles even with this in the passive state notes. I still have the armor set to <Passive State: 523> but it's not activating.


From the small amount I know about code and whatnot, it feels like the thing you're calling "turnCount" is a variable. Is that something I need to set up myself with what you initially advised? Or is that a hard-coded variable? Really sorry for bothering you with this issue.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
From the small amount I know about code and whatnot, it feels like the thing you're calling "turnCount" is a variable. Is that something I need to set up myself
No, it's created in the Custom Regenerate Effect.
Code:
user.turnCount=user.turnCount || 1;
says "if the turnCount variable already exists, use that value. Otherwise, create it with a value of 1"

And that should be running because your passive condition
Code:
condition=!user.turnCount || user.turnCount<4;
says "if there is no turnCount variable, or if there is and its value is less than 4," so the state should be active at the beginning of battle.

If it's still not working for you, I'll try to take a poke at it, but probably not today.

Here's a little stopgap measure - see if this turns the state on at the beginning of battle and if the counting and turning itself off after 3 turns works correctly.

Create a troop event on Turn 0, and enter the script command
Code:
$gameParty.members().forEach(actor => actor.turnCount=1);
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
No, it's created in the Custom Regenerate Effect.
Code:
user.turnCount=user.turnCount || 1;
says "if the turnCount variable already exists, use that value. Otherwise, create it with a value of 1"

And that should be running because your passive condition
Code:
condition=!user.turnCount || user.turnCount<4;
says "if there is no turnCount variable, or if there is and its value is less than 4," so the state should be active at the beginning of battle.

If it's still not working for you, I'll try to take a poke at it, but probably not today.

Here's a little stopgap measure - see if this turns the state on at the beginning of battle and if the counting and turning itself off after 3 turns works correctly.

Create a troop event on Turn 0, and enter the script command
Code:
$gameParty.members().forEach(actor => actor.turnCount=1);
With the troop event on turn zero, putting that as the only command with the "Script" option like you said, the battle fails to even start beyond the initial half-second with the error:

"Unexpected token =>}"

Take as much time as you need, I feel very guilty about bothering someone who clearly knows their way around this stuff.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
With the troop event on turn zero, putting that as the only command with the "Script" option like you said, the battle fails to even start beyond the initial half-second with the error:

"Unexpected token =>}"
Something is wrong over on your side. As you can see, I don't even have a closing brace in the code, so it can't be reading one to produce an error.

If you typed that, you mistyped something (and should probably double check everything else we've talked about in case there was a typo in there).

If you copy and pasted it, something is wrong. Is your project the latest version of MV? You can check in the index.html file.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
Something is wrong over on your side. As you can see, I don't even have a closing brace in the code, so it can't be reading one to produce an error.

If you typed that, you mistyped something (and should probably double check everything else we've talked about in case there was a typo in there).

If you copy and pasted it, something is wrong. Is your project the latest version of MV? You can check in the index.html file.
I'm using 1.6.1 so think so, yeah.

$gameParty.members().forEach(actor => actor.turnCount=1);

Is the script in the turn 0 troop event. The error just says "Unexpected token =>" not actually sure how that bracket got in there the first time. Maybe I was just tired or something. But yeah either way, the same error occurs with => being unrecognized or something.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
I'm using 1.6.1 so think so, yeah.
Did you double-check in your html file as I mentioned? If you started this project a while ago, the editor software updating would not do anything to your project unless you manually patched it.

$gameParty.members().forEach(actor => actor.turnCount=1);

Is the script in the turn 0 troop event. The error just says "Unexpected token =>"
I can't replicate this in a new project. It sounds like your game is running an older version of JavaScript that doesn't support the arrow function, which is why I asked what version your project is. That could also affect some of the other problems you've had in this thread.

It works fine for me. If your index.html confirms that your project is 1.6.1 or 1.6.2, try turning off all of your plugins, although I don't see how that could affect your JS parser.

Try making a new project and sticking it in there.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
Did you double-check in your html file as I mentioned? If you started this project a while ago, the editor software updating would not do anything to your project unless you manually patched it.


I can't replicate this in a new project. It sounds like your game is running an older version of JavaScript that doesn't support the arrow function, which is why I asked what version your project is. That could also affect some of the other problems you've had in this thread.

It works fine for me. If your index.html confirms that your project is 1.6.1 or 1.6.2, try turning off all of your plugins, although I don't see how that could affect your JS parser.

Try making a new project and sticking it in there.
Oh boy. This gets more and more embarrassing for me, really feel like this isn't getting anywhere. index.html launches in chrome, with the error message "failed to load: data/Actors.json

I'm assuming that means it's going to fail to load way more than just that.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
Oh boy. This gets more and more embarrassing for me, really feel like this isn't getting anywhere. index.html launches in chrome, with the error message "failed to load: data/Actors.json
No - you weren't supposed to try to run the HTML file in a browser. That's what your Game.exe is for.

Right-click index.html and Open With Notepad to read the text contents of it.

But also, I said the wrong file :guffaw:

Do that with your Game.rpgproject file, that's the one that says the project version :rolleyes:
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
4,646
Reaction score
3,778
First Language
EN
Primarily Uses
RMMZ
I'm using 1.6.1 so think so, yeah.
Is that the version number displayed in the editor, via Help -> About?

$gameParty.members().forEach(actor => actor.turnCount=1);
Here's a version that ought to be compatible with older versions of JavaScript:
JavaScript:
var members = $gameParty.members();
for (var n = members.length; n--;)
  members[n].turnCount = 1;

The error just says "Unexpected token =>"
This is an issue with your RMMV installation. The runtime environment (NWJS) that your editor's playtest is using is an older version that does not support features from ES6 (newer version of JavaScript) like arrow functions: arg => etc. These features aren't essential, but if you are running v1.6.1 then they should be supported.

For diagnostic purposes, you can press F8 during playtest to show the dev tools window. Make sure you're on the Console tab of that window, type this in, then press Enter:

process.versions.nw
This should show the NWJS version that the playtest is using:

screenshot.jpg

You could try updating/reinstalling RMMV to see if that helps:

Oh boy. This gets more and more embarrassing for me, really feel like this isn't getting anywhere. index.html launches in chrome, with the error message "failed to load: data/Actors.json
This is expected. Your browser, for security reasons, is probably set to block pages from reading files on your system.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
No - you weren't supposed to try to run the HTML file in a browser. That's what your Game.exe is for.

Right-click index.html and Open With Notepad to read the text contents of it.

But also, I said the wrong file :guffaw:

Do that with your Game.rpgproject file, that's the one that says the project version :rolleyes:
Ah :rswt
Well it says 1.0.1 so yeah definitely not current. I do remember making this project when I very first got the program years ago, and then it just updated at some point.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
Is that the version number displayed in the editor, via Help -> About?


Here's a version that ought to be compatible with older versions of JavaScript:
JavaScript:
var members = $gameParty.members();
for (var n = members.length; n--;)
  members[n].turnCount = 1;


This is an issue with your RMMV installation. The runtime environment (NWJS) that your editor's playtest is using is an older version that does not support features from ES6 (newer version of JavaScript) like arrow functions: arg => etc. These features aren't essential, but if you are running v1.6.1 then they should be supported.

For diagnostic purposes, you can press F8 during playtest to show the dev tools window. Make sure you're on the Console tab of that window, type this in, then press Enter:

process.versions.nw

This should show the NWJS version that the playtest is using:

View attachment 245889


You could try updating/reinstalling RMMV to see if that helps:


This is expected. Your browser, for security reasons, is probably set to block pages from reading files on your system.

OH MY GOSH AAAGHH
This issue has been plaguing me for months now and this actually worked. The "old javascript" code you whipped up worked in initial testing, combined with the state script Turan thought of. That's incredible, it does exactly what I was hoping.

No state on map or turn 0
State as soon as turn 1 actions commence
State removed at the end of turn 3, right before turn 4 actions are called

This is incredible. I'll obviously keep testing it and stuff, but this is exactly what I was hoping for I'm so happy lol. Thank you guys so much, if there's another issue with it I'll ask here again.
 

xyzeden

Veteran
Veteran
Joined
Oct 16, 2021
Messages
38
Reaction score
7
First Language
English
Primarily Uses
RMMV
Okay, so I've gone through all my items that give passive states in this way, and they all work flawlessly with the methods described above (even managed to make a conditional state where it "stacks" every 3 turns, which is cool). Also went through every single troop and added the event to ensure that it activates in each battle.

But there is one final problem:

Having two of these items equipped at the same time does in fact mess up the "turnCount" counter. Meaning if I have an item that provides a +200% target rate for the first three turns, and an item that provides a +20% M.ATK boost in the first three turns, both items add a turnCount each turn, meaning both items durations are messed up and they end early.
 

Anastasius

Veteran
Veteran
Joined
Feb 7, 2022
Messages
59
Reaction score
45
First Language
English
Primarily Uses
RMMV
Hello @ATT_Turan and @caethyril. :kaoswt2: The turnCount property is added to actor objects by Yanfly's Battle Engine Core at game start.

Hi @xyzeden. :kaohi:You don't actually need troop events since ATT_Turan's original solution would work if you use a different variable name for the counter of each passive state (e.g. turnCountTGR, turnCountMAT) so they don't stack. You may also need to add $gameParty.inBattle() in the passive state condition.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
8,908
Reaction score
6,717
First Language
English
Primarily Uses
RMMV
Hello @ATT_Turan and @caethyril. :kaoswt2: The turnCount property is added to actor objects by Yanfly's Battle Engine Core at game start.
I don't see that in the plugin. It adds a _selfTurnCount member variable, but I haven't looked into when that's incremented - I would assume that it lines up with when the battle turn count increases, so that wouldn't match what the OP is trying to do.

you use a different variable name for the counter of each passive state
That's exactly right.

Ah :rswt
Well it says 1.0.1 so yeah definitely not current. I do remember making this project when I very first got the program years ago, and then it just updated at some point.
I strongly recommend that you update your project files. That far back you're going to still have bugs in the engine code that got fixed later on, and I'm amazed that you're not running into more problems with plugins being incompatible with that deprecated code.

It's very simple to patch your project, just follow the instructions.
 

Latest Threads

Latest Profile Posts

Now a videogame developer has been arrested in Japan for insider trading. Darn blue hedgehog! XD
The forum stalled for a second and I thought I got banned for using 1 swear word. :kaoswt2:
Today years old when I realized I can track Last Skill ID used as a variable... natively in engine....

*sighs in reconstructing skill system*

Forum statistics

Threads
131,751
Messages
1,222,920
Members
173,501
Latest member
Alexcrawler
Top