Get the array length of states in a condition?

Silverskin

Villager
Member
Joined
Jun 21, 2016
Messages
27
Reaction score
11
First Language
English
Primarily Uses
Hey,


for a skill that cures all negative states, I want to write a pice of my own code inside Yanflys action sequence. It looks like this:

<target action>
for (var i = 0; i < $dataStates.length; ++i){
  if (target.isStateAffected(i)){
    if ($dataStates[stateId].meta.good){
    }
    else{ 
    target.removeState(i);
    }
  }
}
</target action>
the ".meta.good" is already coded elsewhere and works perfectly fine. It flags states as good and not affected by luk's chance of not getting it.


The two errors I keep getting are: i is undefined or unexpected token {.


However, $dataStates is an array of which you can check the array length (at least I think you can), and I literally checked these brackets 20 times and they are correct.


If you could help me with that skill and that specific line of code, I would be really thankful!
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
515
Reaction score
682
First Language
English
Primarily Uses
RMMV
Usually you want to do i++, instead ++i.


<target action>
for (var i = 0; i < $dataStates.length; i++) {
if (target.isStateAffected(i)) {
if ($dataStates[stateId].meta.good) {
//Do nothing
}
else{
target.removeState(i);
}
}
}
</target action>

//Optional

<target action>
var i = 0;
for (i < $dataStates.length; i++) {
if (target.isStateAffected(i)) {
if ($dataStates[stateId].meta.good) {
//Do nothing
}
else{
target.removeState(i);
}
}
}
i = 0; //Reset i
</target action>




I think that should help with i is undefined issue, hopefully.
 

Silverskin

Villager
Member
Joined
Jun 21, 2016
Messages
27
Reaction score
11
First Language
English
Primarily Uses
thank you for the quick reply!


I am a javascript noob and I will still have to learn much about math and variables.


Unfortunately, I keep getting the unexpected token { error, so I cant tell whether this has fixed it for sure.


I will go through all of yanflys tutorials again and look if he has some similar code in his tutorials.


I will reply again when I found a solution. Good night!
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
515
Reaction score
682
First Language
English
Primarily Uses
RMMV
I was thinking, since you seem to be getting a token error, we can remove some braces. @Saathan


<target action>
var i = 0;
for (i < $dataStates.length; i++) {
if (target.isStateAffected(i)) {
if ($dataStates[stateId].meta.good)
//Do nothing
else
target.removeState(i);
}
}
i = 0; //Reset i
</target action>




Hopefully that will fix the error. If that doesn't fix the error, it might be the other braces in this call.
 

Silverskin

Villager
Member
Joined
Jun 21, 2016
Messages
27
Reaction score
11
First Language
English
Primarily Uses
Hi,


I finally got that unexpected token error. Yanfly's Action sequence doesn't even support brackets and the "for var..." loop.


That's why both of my errors occured. I will try to run this with a custom eval code within action sequence or via a common event script call.


Ill post a solution if I find one.
 

Silverskin

Villager
Member
Joined
Jun 21, 2016
Messages
27
Reaction score
11
First Language
English
Primarily Uses
I FOUND A SOLUTION


Yanflys Action sequence has problems processing more complicated codes (or I am just too dumb to figure out how), even when using the eval code.


Instead of putting the code into <target action>, leave it blank and use Yanflys Skill Core plugin. Before the Action sequence stuff, I put:

<After Eval>


for ( var i = 0; i < $dataStates.length; i++) {


if (target.isStateAffected(i)) {


if ($dataStates.meta.good) {


}


else {


target.removeState(i);


break;


}


}


}


</After Eval>
and it worked perfectly!


I hope this helps everyone that has the same problem as I had, and thank @Kino for the help :)


Edit: Put squared brackets with an i inside after $dataStates and before .meta, this forum cant show squared brackets somehow.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

On the plus side, if all this rioting sparks another Covid outbreak... I will have a whole lot of time to work on my game. Not exactly how I wanted to get that time, but hey I'm a glass is half full... of RM kind of guy. :LZSwink:
A video once in a while won't hurt.
Have a craving for a Nesquik milkshake. No idea why. Haven't had one since I was a kid. lol. I remember them kinda tasting nice, but also leaving a lot of nasty powder at the bottom of the cup.
The more I think about it, the weirdest part of going to work post-virus will probably be getting used to seeing my coworkers' mouths again. :LZYshock:
I think one of my weirdest realizations is that my speed of game development would probably be about the same if I *didn't* work a full-time manual labor job.

Forum statistics

Threads
98,059
Messages
948,974
Members
129,340
Latest member
guangdi
Top