How to create/use Arrays?

Hi!
I have been workin on RPGZ for some years but I have done it with close to 0 programming knowledge so here's one of my many questions : how to create and, of course, use arrays?
Some examples of what I wanna do is to create many many many different dialog options for each character, with some also based on other variables but let's keep that for later.
I have like 1% knowledge of arrays from highschool but I feel like I know nothing.
So, how do I create an array for dialogs?

Other question, still about arrays, how to have variables working (if it's possible) in them?
Like, numbers of other variables appearing and/or certain options becoming avaiable or not depending on certain variables values.

Like I said, I have no knownledge of this so my questions may appear dumb, sorry.

P.S. : I am gonna have many other questions in the future ^^
creating arrays is simple as simple as:

let something = []; // empty array

you can push things into it or set things in there by default

let msg = ["hi", "hello", "how do you do?"]
$gameMessage.add[msg[1]) put out "hello".
To expound a bit...you can use any game variable as an array, but because you then need to interact with it via script (it won't work with the editor's event commands anymore), it might end up being more complicated for you than just using a number of variables.

You can Google "JavaScript arrays" and find tutorials on how to use them, reference them, add elements, etc. I'm not going to go through all of that.

But for the sake of specific to RPG Maker, you can do something like this as a Script event command:
Code:
$gameVariables.setValue(69, ["Yo", "What's up?", "I want lunch.", "My knee!"]);

Now variable 69 is an array and you can access those different messages starting at index 0. So
Code:
$gameVariables.value(69)[2]

will produce "I want lunch."

However, as I mentioned, you can't use the \V escape code in Show Text boxes to reference that anymore. So you'd need to either use another plugin, like Hakuen Studio's Escape Codes to be able to embed JavaScript in your Show Text, or you'd need to produce the entire message window via script commands.

Whereas taking up 4 separate variables set to those messages - you can use the Script option in Control Variable to assign a "text string" to a variable - you can use all of the regular event commands to choose a random one and display it in a Show Text window.
Could you give an example of a dialogue that you want to construct in this way? Because if it's just random messages, As ATT_Turan says this can be done without coding by creating a random number and event branching depending on the random number. If however you want elaborate composite texts, you'd need a plugin to wordwrap the text you generated, otherwise it will just overflow on one row.
Could you give an example of a dialogue that you want to construct in this way? Because if it's just random messages, As ATT_Turan says this can be done without coding by creating a random number and event branching depending on the random number. If however you want elaborate composite texts, you'd need a plugin to wordwrap the text you generated, otherwise it will just overflow on one row.
Example : I have 10 anger levels for a certain NPC (anger level increases if you try to approach said NPC by any other direction than face to face, each and every time you lose of of the challenges she offers, etc... On the other hand, winning battles and talking face to face will reduce the anger level) and around 31 random dialog options for each level.
Atm, I have a dozen miles long army of IFs, with a random number generator which gives a number between 0 and 30 each time but I feel like arrays would make stuff easier, better looking and, most importantly, cleaner for me to work with.
I am planning to make stuff like this for most of the characters in my game, with also dialogs based on party members, health, enemy, etc...
I am just trying to understand how much arrays might be helpful in my situation but also cause I wanna learn how to master RPGZ
I wouldn't bother using an array for this - I don't see how it's helpful.

You still have to type out all of the message options in the editor someplace to set them as elements of an array, so you might as well just type them into a regular Show Text command and then everything works with the default event commands without any further array manipulation.

I would organize it by having a separate event page for each anger level, and each one has the same event structure (which you can make one time on one page then just copy and paste onto the others).

Set a variable to a random value between 1-31, then have a Conditional Branch for each value with a Show Text inside of it.

You make that once, copy and paste the event page however many times. Then all you need to do is set the Condition on each event page and click into the individual Show Text commands to enter the dialogue.

It would be just as much typing to enter all of the dialogue as elements of an array, then it would be more work to use code to produce the random value and message window than it is to click the event command buttons.

I am just trying to understand how much arrays might be helpful in my situation but also cause I wanna learn how to master RPGZ
Personally, I feel the opposite. I think mastery of MZ is indicated by fluency with its built-in systems such as eventing.

I'm not saying you shouldn't learn JavaScript to be able to enhance what you can do, but even people who are proficient coders don't use it for everything - understanding when you actually improve your efficiency by using code vs. events is important.
I wouldn't bother using an array for this - I don't see how it's helpful.

You still have to type out all of the message options in the editor someplace to set them as elements of an array, so you might as well just type them into a regular Show Text command and then everything works with the default event commands without any further array manipulation.

I would organize it by having a separate event page for each anger level, and each one has the same event structure (which you can make one time on one page then just copy and paste onto the others).

Set a variable to a random value between 1-31, then have a Conditional Branch for each value with a Show Text inside of it.

You make that once, copy and paste the event page however many times. Then all you need to do is set the Condition on each event page and click into the individual Show Text commands to enter the dialogue.

It would be just as much typing to enter all of the dialogue as elements of an array, then it would be more work to use code to produce the random value and message window than it is to click the event command buttons.


Personally, I feel the opposite. I think mastery of MZ is indicated by fluency with its built-in systems such as eventing.

I'm not saying you shouldn't learn JavaScript to be able to enhance what you can do, but even people who are proficient coders don't use it for everything - understanding when you actually improve your efficiency by using code vs. events is important.
ok, thank you for the help

Original thread: https://forums.rpgmakerweb.com/threads/how-to-create-use-arrays.162469/