[SOLVED] Arrays?

Alador

The Mage of Mythix
Veteran
Joined
Apr 16, 2020
Messages
109
Reaction score
59
First Language
English
Primarily Uses
RMMV
Hey everyone, do you know how you would make an array in rpg maker MV? Thanks!
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,560
Reaction score
904
First Language
Portuguese - Br
Primarily Uses
RMMV
Hi!
You can make it in the same way that is made on Javascript:
let myVariable = []

But if you mean using the game variables:
$gameVariables.setValue(ID, []);
 

Alador

The Mage of Mythix
Veteran
Joined
Apr 16, 2020
Messages
109
Reaction score
59
First Language
English
Primarily Uses
RMMV
Hi!
You can make it in the same way that is made on Javascript:
let myVariable = []

But if you mean using the game variables:
$gameVariables.setValue(ID, []);
Thanks so much, this is really helpful! But, is there a way to add a value to the array, like, there is already data in the array and you just add another value to it?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
526
Reaction score
230
First Language
English
Primarily Uses
RMMV
If it's in a variable, and you know it's an array already:

JavaScript:
$gameVariables.value(ID).push(newValue);
To add it to the beginning instead of the end:

JavaScript:
$gameVariables.value(ID).unshift(newValue);
Or in the middle:

JavaScript:
$gameVariables.value(ID).splice(newIndex, 0, newValue);
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,560
Reaction score
904
First Language
Portuguese - Br
Primarily Uses
RMMV
Oh, yes!
You can use this:
$gameVariables.value(ID).push(Value)
$gameVariables.value(ID).unshift(Value)

push > Add a new item in the final position of the array.
unshift > Add new item on the first position of the array.

But you will not be able to reference it on the message window with \v[id], it will not return the array.
But you can use:
$gameVariables.value(ID)[index]
Where the index is the value of the array position you are looking for. Always start with zero.
 

Alador

The Mage of Mythix
Veteran
Joined
Apr 16, 2020
Messages
109
Reaction score
59
First Language
English
Primarily Uses
RMMV
If it's in a variable, and you know it's an array already:

JavaScript:
$gameVariables.value(ID).push(newValue);
To add it to the beginning instead of the end:

JavaScript:
$gameVariables.value(ID).unshift(newValue);
Or in the middle:

JavaScript:
$gameVariables.value(ID).splice(newIndex, 0, newValue);
Oh, yes!
You can use this:
$gameVariables.value(ID).push(Value)
$gameVariables.value(ID).unshift(Value)

push > Add a new item in the final position of the array.
unshift > Add new item on the first position of the array.

But you will not be able to reference it on the message window with \v[id], it will not return the array.
But you can use:
$gameVariables.value(ID)[index]
Where the index is the value of the array position you are looking for. Always start with zero.
Thank you so much! This is super helpful.

EDIT: Sorry for asking so many questions, but is there a way to see if a static value is equivalent to any of the values in the array?
 
Last edited:

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,560
Reaction score
904
First Language
Portuguese - Br
Primarily Uses
RMMV
Yes, there is a lot of ways of doing that.
That is a simple one:
let myArray = [10, 5, 3, 'ball']
let value = 3;
let result = myArray .includes(value) // It will return true if myArray contains the value, and false otherwise.
 

Alador

The Mage of Mythix
Veteran
Joined
Apr 16, 2020
Messages
109
Reaction score
59
First Language
English
Primarily Uses
RMMV
Yes, there is a lot of ways of doing that.
That is a simple one:
let myArray = [10, 5, 3, 'ball']
let value = 3;
let result = myArray .includes(value) // It will return true if myArray contains the value, and false otherwise.
That is exactly what I needed, thanks so much!
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

I just like this website:
lol
I streamed Moonfall on 9/25/20
and have started a page to showcase my vids/stream :kaoluv:

Please subscribe and follow, it's free, it's quick and one sub means so much to me, it would really make my day~ :wub

And now to face my worst enemy... adding color :kaocry:
Power has been restored FINALLY to our home in Lake Charles. Hurricane Laura tried to wreck our lives and disrupt my work on the commercial project i have going with Cloud 9 but the key word is TRIED!!! Slowly moving from the shelter to home over the next week or so. I WILL NOT QUIT!
I am happy because the RPG Maker MZ character comes with extra bust and full body art, but I am disappointed because the quality of the character's PIxel art has decreased.
Only My Opinion that Pixel art MV is better.

Forum statistics

Threads
103,228
Messages
998,189
Members
134,718
Latest member
Weaver
Top