Random Var Script Call Error

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
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
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,779
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?
 
  • Like
Reactions: Loz

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
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
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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.
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,779
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?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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.
 

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
First Language
Italian
Primarily Uses
RMMV
Thank you thank you!
Like this? But it still won't work :LZSteary:;_;
Untitle2d-1.jpg
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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))
 

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
First Language
Italian
Primarily Uses
RMMV
Just done so, still won't work...
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,779
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
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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:

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
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...
 

Attachments

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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
 

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
First Language
Italian
Primarily Uses
RMMV
I see, how do I find out where 665 is?
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,779
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
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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
 

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
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
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,696
Reaction score
3,006
First Language
Tagalog
Primarily Uses
RMVXA
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
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
621
Reaction score
2,779
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?
 

Loz

Veteran
Veteran
Joined
Sep 5, 2019
Messages
42
Reaction score
13
First Language
Italian
Primarily Uses
RMMV
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?
After the error popup what happens is I get this text shown in game:

Selected message 0

And nothing else
 

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

Latest Threads

Latest Posts

Latest Profile Posts

The most rewarding part of making custom body character parts is absolutely not making the masks work. Somebody please put me out of my misery.
Any commercial devs here ever mess with Gamejolt? Been contemplating making my games available there but don't know if it's worth the effort or not.
Social distancing taught me of how much of not a loner I am. Dammit, I miss seeing my friends...
Happy 4th of July all. Anybody have plans? Mine here is staying home away from the virus. Still a nice 3 day weekend.
The project I am working on is going great at the moment. I'm hoping everyone is having as successful a time as I am. :)

Forum statistics

Threads
99,258
Messages
963,571
Members
130,847
Latest member
Xephiers
Top