Random Var Script Call Error

You don't have a Phone Texts = 0 handler.
EDIT : Ignore that, I was thinking of something else.

Are you looping this in some way? How are you activating this event?
standardplayer - can you show your test code? I want to check some things out 🙂

He shouldnt be getting 0 in the first place as the array is only from 1-8... If the randomization of the array contents give him 0, there is something wrong happening. Yanfly's error report points to an error in his second block of code.
aaa.jpg
The event is just below the characters, I want him to get messages when checking the phone
Wait, I'm getting 0 as my result sometimes, like Loz's issue shows. Lemme figure out why real quick >< 0 shouldn't be getting returned at all
Yeah, the randomization looks fine too as doing it as randomInt(.length) should be returning from 0 to length-1 only anyway, so it should work correctly within the array as the indexes are from 0 to length-1 too...

Or does the JS randomInt actually randomizes to the last value?

Loz - does it always return 0 to you? or just sometimes?
LozTest.png



This works for me. I confirmed in the console that I'm getting no 0 returned, and I (before the screenshot) had a console log to confirm the array was initializing every time it was empty, and it is.

Clever init/reinit condition set there, btw. Threw me off at first.
Because the first time, it asks if the .length property exists, but after this, when the array runs out, when it asks for length it gets 0, which gets read as false.

I think @Engr. Adiktuzmiko said that second part already, but still. Double usage, clever.
View attachment 125809


This works for me. I confirmed in the console that I'm getting no 0 returned, and I (before the screenshot) had a console log to confirm the array was initializing every time it was empty, and it is.

Clever init/reinit condition set there, btw. Threw me off at first.
Making sure I get this right, the differences are:
You replaced 'var' with let, and added the console.log line of code
Pretty much. And replacing 'var' with 'let' really shouldn't change your result, here....
There has to be something else affecting variable 1, somewhere. Its the first variable everyone uses, try changing the references to variable 1 to an unused variable.
Loz - can you manually retype your second script block?

because looking at it right now, you seem to have extra : on the start of your lines. Which is probably because you copy pasted your code directly from the other thread

That would actually explain why Yanfly's Util is giving you Illegal Error, and why the text variable is always 0.
@Engr. Adiktuzmiko Wins!
That may be why I tried replacing with Let, and still get error and '0' as a result.
Also I don't see the extra :, I don't think I can type it I don't know what I would be typing.
So looks like we're back at square 0? 😀
If you're curious would packing this demo of a game and wetransfer it over for you to have a look an option?
Is it!? I can't see it
Loz - type what standardplayer typed, exactly as it is, without any :


Dont copy paste code from a thread, especially if its not actually formatted using the CODE block. You might end up copying extra stuff.

For example, what standard posted was a screenshot, if you copy paste the code directly from it, you would end up copying the : again
No @Loz that's it, I didn't see it because I was only looking at the JS lines, but yeah, actually go to that command, hit spacebar to open the script box, and get rid of any : at the beginning of the lines.

The : colons are actually part of RPG Maker's event editor, I know it looks like they're part of what's in the script box but they aren't.

@Engr. Adiktuzmiko good find! I'm so used to seeing them in the Event Editor I didn't even notice!
Oh my god YES! YES! It works! I am so happy you guys thank you so much!
:LZScheeze::LZScheeze::LZScheeze::LZScheeze:
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?

No @Loz that's it, I didn't see it because I was only looking at the JS lines, but yeah, actually go to that command, hit spacebar to open the script box, and get rid of any : at the beginning of the lines.

The : colons are actually part of RPG Maker's event editor, I know it looks like they're part of what's in the script box but they aren't.

@Engr. Adiktuzmiko good find! I'm so used to seeing them in the Event Editor I didn't even notice!

I only noticed it after you posted your own code lolz. That was only when I realized that he has extra : in there

If you didnt post your event code, I wouldnt have noticed it too.
How many years have you guys been at this?
About a decade now maybe, being in this forum is like a very normal part of my life now. xD
Wow! Gives me some hope as a total noob. Well thanks again and catch you around!
Maybe five years for me. Good luck making your game, glad you reached out and reach out if again if you run into any problems 😀

Original thread: https://forums.rpgmakerweb.com/threads/random-var-script-call-error.114457/