$dataMap.events.filter not working ?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
hi.


What am doing wrong.


I try many way but its return all way error in console log.


Am try get a list of all Event have spécific name in the the $dataMap.events[x]._name 


What am do bad ?
How to do this ?


Var NumGalaxi = $dataMap.events.filter(function(event) {
return event._name.includes('soleil');
});


Tanks
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
854
First Language
English
Primarily Uses
RMMV
The 'v' in 'var' is uppercase, which will cause an error. Also, $dataMap.events has a null entry at position zero, so you need to check to see if each entry actually exists.

Code:
var NumGalaxi = $dataMap.events.filter(function(event) {
                    if (event) return event.name.includes('soleil');
                });
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
The 'v' in 'var' is uppercase, which will cause an error. Also, $dataMap.events has a null entry at position zero, so you need to check to see if each entry actually exists.



var NumGalaxi = $dataMap.events.filter(function(event) {
if (event) return event.name.includes('soleil');
});


Ok, i just found i way,  i found this is work.


What the difference ??

Code:
$dataMap.events.filter(function(event) {
        return event && event.name=="soleil";
    });
 
Last edited by a moderator:

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
854
First Language
English
Primarily Uses
RMMV
Basically the same thing as I showed above, just using different code.


My code >> If the event is not undefined (exists), then return if the event name includes 'soleil'.


Your code >> return if the event is not undefined (exists) and also the name of the event is equal to 'soleil'.


The original code caused an error because we are trying to call the 'includes' method. We cannot call the 'includes' method on an undefined variable.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Basically the same thing as I showed above, just using different code.


My code >> If the event is not undefined (exists), then return if the event name includes 'soleil'.


Your code >> return if the event is not undefined (exists) and also the name of the event is equal to 'soleil'.


The original code caused an error because we are trying to call the 'includes' method. We cannot call the 'includes' method on an undefined variable.
ok tanks for this explaine.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

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.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top