Random Var Script Call Error

Discussion in 'RPG Maker MV' started by Loz, Oct 22, 2019.

  1. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hello dear colleagues: is this the right place for my query?
    To those experts among you who understand this language...what am I doing wrong?
    I am trying to have a message show up randomly, and only once.

    Thank you for any feedback!

    Untitle2d-1.jpg
     
    #1
  2. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    410
    Likes Received:
    1,549
    First Language:
    English
    Primarily Uses:
    N/A
    There's no comparison operator in the first conditional Branch's condition. Without a comparison like == or something, it's just asking if the variable exists. Since you have ! in front of it, it's asking if the variable DOESN'T exist.
    So for starters, your array isn't getting populated.
    As a result, the random number isn't getting assigned. It's basically asking for
    Math.randomInt(0)

    EDIT: Unless the initial value for Variable 9 is getting set elsewhere before this?
     
    #2
    Loz likes this.
  3. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Hi!
    Nothing else is being set elsewhere to my knowledge.
    I am glad you identified the problem, but I don't know anything about Java.. so I'm assuming I need to add a '=' symbol around here: !$gameVariables.value(9).length ??
    Makes sense that it is not getting populated as after the error window I get: the var is 0

    I was blindly copying this:
    70652910_3016306671729235_7397983559933231104_n.png
     
    #3
  4. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Try

    !gameVariables.value(9).length > 0

    or > 1

    If you want to check for "equal" that is == or ===, using = means you're actually setting a value, not checking it.

    The original check doesnt work because actually, gameVariables are being set to zero initial value by default (or more like its forced to return as 0 if it doesnt exist yet), so in essence, it has a length of 1. Your original check was like "if length doesnt exist", since it exists, the condition turns false.
     
    #4
  5. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    410
    Likes Received:
    1,549
    First Language:
    English
    Primarily Uses:
    N/A
    Now that I'm looking again, the first condition is actually fine. It's just checking for the .length property to see if the array has been created yet.
    What is this supposed to be doing? Because it looks like its just getting a random number between 1 and 9, but doing it in a roundabout way.
    What is your current result?
     
    #5
    Engr. Adiktuzmiko likes this.
  6. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    The check returns false probably because it returns a length of 1. Meaning, the length exists, and the check is "if length does not exist".

    When you call the .value function of $gameVariables, the game forces it to return 0 if the variable has not been set yet to avoid error prompts (which can happen if it returns NULL, nil, whatever)... Since the variable is actually returning a value, the length property still counts it, and thus, length exists.

    So your suggestion of putting an evaluation for a value (possibly, > 1) should fix it.
     
    #6
    standardplayer and Loz like this.
  7. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Thank you thank you!
    Like this? But it still won't work :LZSteary:;_;
    Untitle2d-1.jpg
     
    #7
  8. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Try > 1 instead of 0... because, read previous statement

    or maybe, a safer approach is to check if the variable is an array

    !Array.isArray($gameVariables.value(9))
     
    #8
    standardplayer likes this.
  9. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    Just done so, still won't work...
     
    #9
  10. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    410
    Likes Received:
    1,549
    First Language:
    English
    Primarily Uses:
    N/A
    What I'm seeing is that the rest of the code needs and array to exist inside of variable 9. When you ask
    if(!$gameVariables.value(9).length) you're asking if the property exists. If it doesn't, in the event above, thats when it makes an array. I think that whole top condition is actually for initialization purposes.
    It's hard to know without more info on what OP is trying to accomplish though.

    @Loz, what is the result though, tell us more than just that it doesn't work
     
    #10
    Engr. Adiktuzmiko likes this.
  11. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Check my other suggestion then...

    PS: To be sure what is happening with the original code, try putting a script call like this before your conditional

    console.log($gameVariables.value(9).length)

    Then playtest with the console on and see what value gets printed. That way we can know if the problem lies with the length or not

    And yeah, what exactly happens on your tests? Saying it doesnt work is a bit too vague

    PS: Wait wait wait

    on your setting of var scList, you have set it to $gameVariables.value(9) > 0

    Please remove the > 0 in there

    What will happen with that code is that it will store either true or false, not the array saved in Variable 9...
     
    Last edited: Oct 22, 2019
    #11
  12. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    The OP was also trying to have a random variable drawn from a finite list once per each variable until the list has no more numbers in it.
    As I test I get this kind of window... I don't know what a console is I am sorry feel like a 6 year old right about now...
     

    Attached Files:

    • 221.jpg
      221.jpg
      File size:
      271.6 KB
      Views:
      8
    #12
  13. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    It says line 665 has an illegal error.. What is line 665 in Yanfly's Passive state?

    And does your event have something to do with Yanfly's passive states? Because the error points to Yanfly's Passive States...

    Could you have used variable 9 or 1 in Yanfly's plugin? That could be causing the problem
     
    #13
    standardplayer likes this.
  14. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    I see, how do I find out where 665 is?
     
    #14
  15. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    410
    Likes Received:
    1,549
    First Language:
    English
    Primarily Uses:
    N/A
    I checked auto passive states, it doesn't seem to reserve variables. I used to get weird Yanfly errors but they often didn't have to do with the actual Plugins, but rather something I did in my own JS. I'm just gonna go ahead and recreate the environment and try to figure it out.
    @Engr. Adiktuzmiko might beat me to it though
     
    #15
    Engr. Adiktuzmiko likes this.
  16. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    Looking at the error, it seems to error at Yanfly's passive state plugin after the setValue for variable 1. So maybe, you are using Variable 1 in Yanfly's Passive plugin, and your event setting it to a different value is then causing a problem with Yanfly's code.

    Check line 665 of Yanfly's Autopassive state plugin coz thats where the error is pointing. If you could maybe post a screenshot containing line 665 and the surrounding code, it would be good.

    @standardplayer - its weird though if the plugin itself doesnt use them, as the error is clearly pointing to Yanfly's autopassive state plugin (line 665 to be exact).

    Or maybe its a different plugin or code which Yanfly's autopassive state calls in line 665.

    I dont have RM with me atm so I'll leave the checking to you xD
     
    #16
  17. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    I don't think I have no, I have used passive states but not in relation to a variable. I have now removed the > 0 and keep getting the error as initially did.
    Could this below be what you're looking for? console.jpg
     
    #17
    Engr. Adiktuzmiko likes this.
  18. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    So its actually Yanfly's error reporting... So the actual error is indeed somewhere else, Yanfly's plugin just seems to report it..

    Looking at how Yanfly's error report is coded, the error is happening at your second script block (the one with the var scList and stuff), but I cant find what is wrong with it at first glance.

    I suspect its with the scId part, but Im not too versed with the splice function so I could be wrong, but while waiting, maybe you can try removing the [0]?

    Lets wait what happens with standardplayer 's tests
     
    #18
  19. standardplayer

    standardplayer Keeper of Kitties Veteran

    Messages:
    410
    Likes Received:
    1,549
    First Language:
    English
    Primarily Uses:
    N/A
    Ok, so I tested the code shown in the first event. It works correctly. @Loz, please confirm what is happening that's making you say this isn't working? Ignore the console for a moment, what is happening when you activate this event in game? With the original code you had from the first post?

    EDIT: To confirm, I'm showing variable 1 getting a random number from the array stored in Variable 9, and Variable 9 is both initializing and splicing properly.

    The main reason I ask is because this event is Action button activated, and has no graphic and the same priority as a character. So its invisible....did you mean to autorun this?
     
    #19
  20. Loz

    Loz Veteran Veteran

    Messages:
    42
    Likes Received:
    13
    Location:
    Thailand
    First Language:
    Italian
    Primarily Uses:
    RMMV
    After the error popup what happens is I get this text shown in game:

    Selected message 0

    And nothing else
     
    #20

Share This Page