Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Question about sort by type


In the level the Two Flowers I wanted to command my soldiers with a function but the peasant is also a friend so is there a way to filter the peasant out of the array since I do not know the place in the array(otherwise I would manually remove it)


hector is a different type than your soldiers


I know that I want to know how to remove him from the array

  1. If you are using find friends why do you want to run over the array twice, once to remove hector and once to tell your soldiers what to do. (which was what my answer is saying: hector is of a different type . . . so ignore type of hector and do what ever with the rest.)

  2. If you only have one type of soldier use the find by type “soldier”. then hector is never in the array.
    If you have more than one type of soldier, there is a good chance you are telling them to do different things based on type so either go back to #1, or put each type into a different array, and there again, no hector.

  3. You never say what language you are using so don’t really want to know a (specific language) coding answer, and yet you reject the general case non-coding answer.


A “building from scratch” structure

A removing from array approach

(baby in my arms, can’t write much)


Okay then I want to know how to remove hector from the array in JS


Google: javascript remove from array

looks like you want to pretend the array is a piece of movie film and splice that bad boy right out of the picture.


To tell you the truth I kinda want to


Okay thank you Vlevo

for refs

I used the following command to remove the first element knowing that hector will always be first

friends.splice(0, 1);

Does it actually work? There are some bugs around API protection that might be messing that up in some cases, where you can’t always modify an array that you get as a return value from a function.


Well it worked without error for me