Getting array for $gameMap.event

Hisao Shou

Veteran
Veteran
Joined
Jan 8, 2015
Messages
155
Reaction score
22
Primarily Uses
Hello there, I'm new in javascript programming, and I'm having difficulties to get an array of map ids for $gameMap.event.

I basically want to do Something like:

var arr = [3, 5, 6]; //array of certain events
return $gameMap.event(arr); //returns to any event which has the ids from array

Can someone please help me with this?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
arr is an array and $gameMap.event accepts only an integer.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,091
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
I'm guessing you want to return an array of event objects corresponding to those event IDs? In which case you could try something like this:
Code:
var ids = [3,4,5];
return ids.map(function(id) {
  return $gameMap.event(id);
});
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,682
First Language
English
Primarily Uses
RMMZ
Also, if my memory serves me correctly, $gameMap is an object that only contains information on the current map, not all maps. The game doesn't load all maps to save on memory usage. Data for all maps are kept as json files and are only read (process of taking that info and storing it in $gameMap to replace the data of the old map) when you change map.

(Sorry, I just noticed that you're talking about event ids and not map ids. Your first sentence is confusing me: "I'm having difficulties to get an array of map ids for $gameMap.event.")

For what I think you want to achieve, the above post would be your solution. If it's something else, please be more precise.
 

Hisao Shou

Veteran
Veteran
Joined
Jan 8, 2015
Messages
155
Reaction score
22
Primarily Uses
I'm guessing you want to return an array of event objects corresponding to those event IDs? In which case you could try something like this:
Code:
var ids = [3,4,5];
return ids.map(function(id) {
  return $gameMap.event(id);
});
Thank you very much! This worked
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top