Get the array length of states in a condition?

Discussion in 'Learning Javascript' started by Silverskin, Jul 31, 2016.

  1. Silverskin

    Silverskin Villager Member

    Messages:
    27
    Likes Received:
    11
    Location:
    Germany
    First Language:
    English
    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:

    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!
     
    #1
    Kino likes this.
  2. Kino

    Kino EIS Game Dev Veteran

    Messages:
    515
    Likes Received:
    671
    Location:
    United States
    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.
     
    #2
  3. Silverskin

    Silverskin Villager Member

    Messages:
    27
    Likes Received:
    11
    Location:
    Germany
    First Language:
    English
    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!
     
    #3
  4. Kino

    Kino EIS Game Dev Veteran

    Messages:
    515
    Likes Received:
    671
    Location:
    United States
    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.
     
    #4
  5. Silverskin

    Silverskin Villager Member

    Messages:
    27
    Likes Received:
    11
    Location:
    Germany
    First Language:
    English
    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.
     
    #5
  6. Silverskin

    Silverskin Villager Member

    Messages:
    27
    Likes Received:
    11
    Location:
    Germany
    First Language:
    English
    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:

    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: Aug 2, 2016
    #6
    Kino likes this.

Share This Page