Hi everyone.
Is it possible to deal with arrays or similar in RPG Maker MZ?
I am especially referring to adding a value to a text array stored as variable.
I used to store text value in a variable using the script field and putting the value under quotes; but what if i want to add a new letter to this value?
I need this because I want to implement in my project a room where there are tiles on the floor with the letters of the alphabet: player has to "write" words by passing over the correct tiles, and this would be very easy to do if every new letter could be easily added to the others. I know this could be done in other ways, too, but with a lot of work and using of variables and/or swithces, especially if I wanto to make this thing a repeatable event (with, say, a dozen different words).
Any help?
Are you sure you need an array for what you're trying to do? You might possibly achieve the same result using string methods. However, it greatly depends on your knowledge of JavaScript and how you intend to use it.
You could use the concatenation operator.
Let me give you an example. Let's say I have the word "car," and the player steps on the letter "s," creating the word "cars."
To do this, I'll show you an example in JavaScript:
```
let example = "car";
example += "s";
console.log(example); // output: cars
```
How do we translate this to RPG Maker?
Let’s say your variable 1 is equal to "car."
The player steps on the letter "S."
Variable 1 + (script) "s"
Now your variable will be equal to "cars."
However, I want to warn you about something important. The Visustella multi-language plugin doesn’t work with words defined in this way. So, if you want to make a multilingual game using the Visustella plugin, you won’t be able to, as it doesn’t work with variables containing strings (or at least I haven’t been able to make it work).
Hey everyone,
now I am dealing with how to remove the last element of my array/string.
I have declared a variable as a string with var1 = [ ]
Then I am adding element with $gameVariables.value(1) + "a"
After putting some characters in it, how can I remove the last one?
I've been trying JavaScript commands like pop, lenght or slice, bot I only got some weird results. Probably I am also messing up things with JS's syntax...
Any help?
Thanks in advice!
Or you can forget $gameVariables and use something like $gameSystem.variables to make your own variable list.
For example, you initialize it in the first map of the game.
$gameSystem.variables = {};
Then you can just use something like $gameSystem.variables.stringA = "this is a string value"
Learning how to use Arrays has opened up a whole world of possibilities for me. I highly recommend searching for some RPG Maker tutorials that give examples of using Arrays and you can check out a free online course like W3Schools for JavaScript and you will find lots of useful information. I also just search for specific JavaScript questions and can usually find what I need.
I have some tutorials that highlight different uses of Arrays. My tutorials progressed as I learned more about how to use Arrays and some of those tutorials specifically mention Arrays in the tutorial title or description.
My current Sudoku project uses a LOT of Arrays. For instance, right now, I am using an Array of stored data that I can pull out and use in a Variable to identify other specific Arrays and I use other Variables to identify the position location of the value I want in the appropriate Array. So my script is using Variables to identify both the Array I need to pull data from and the position of that data in the Array.
And 3 years ago, I had zero experience with RPG Maker, programming, and JavaScript.
My best advise is to take a step back, watch a bunch of tutorials and recreate the Array portions yourself in a test project. Read about Arrays and how they are used in a free JavaScript resource and recreate those functions in your test project. Then use your test project to experiment with what specifically you want to do at this time.
Because learning as much as you can about Arrays now, how they work in MZ, all the things you can do with them, will probably greatly expand your options going forward.
And this forum is great for specific questions.
Good luck and embrace the power of the Array!