Is there a downside in extracting or checking all members in a function?

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I was just thinking if there's a downside doing recursion, or checking all the values of an array for a certain value. For example, we have Battle Members or Party members. 

$gameParty.battleMembers()If I want to check if anyone of them has this or that, I'd have to use a for loop, extract each member and then do an if statement saying that if this current index member has this state, then do this.

Is making a loop, checking each value and then doing a condition has a downside? Are there specific or a more professional approach in checking?
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
I was just thinking if there's a downside doing recursion, or checking all the values of an array for a certain value. For example, we have Battle Members or Party members. 

$gameParty.battleMembers()If I want to check if anyone of them has this or that, I'd have to use a for loop, extract each member and then do an if statement saying that if this current index member has this state, then do this.

Is making a loop, checking each value and then doing a condition has a downside? Are there specific or a more professional approach in checking?
why not do:

$gameParty.battleMembers().forEach(something) { ... }then:

Code:
{ return something.doesIhaveCheeseBurger() }
 
Last edited by a moderator:

Amuseum

Veteran
Veteran
Joined
Oct 27, 2015
Messages
71
Reaction score
66
First Language
English Chinese
Primarily Uses
RMXP
loops are fast, simplest, and most versatile, so try that first. you can break out of it early when you find the match. foreach and map are limited in application and performance of the browsers' implementations of them is questionable, and you can't break out of them early.


there are no downside doing recursion if done correctly. in fact, recursion can be many times faster than loops if done properly. but in your case, i don't see why you need recursion.
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
it doesn't sound like you need recursion though .
 

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

Latest Threads

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,072
Members
137,578
Latest member
JamesLightning
Top