index of [anything] in [list]

Sunflower

  • Posts: 591
I'm quite surprised that there's block: "remove [anything] from [ list ]" which removes first occurrence of item in the list, and there isn't block which could just return an index of this item. It kinda doesn't make sense for me, as finding and removing item seems more complex thing to do than finding item itself. Am I wrong here? ^^'

So, could you add block "index of [anything] in [ list ]", which would return the position where the first occurrence is placed (or -1 if it wasn't found)? It's not that creating custom block with the same effect is extremely complex, but it would be nice to have this function already included. ;)

dubealex

  • Posts: 26
I think in As3 the right thing to do would be to do a custom block using the indexOf function, use your list attribute (thats the same as saying use your array variable). I might try to make one later on after work.

coleislazy

  • *
  • Posts: 2607
It would be trivial to make a custom block that does this, but I think the point is that it would also be simple to add a built-in block. Arrays are such a core mechanic when working with tile-based games, that I'm also surprised there isn't this function (not to mention support for multidimensional arrays).

Luyren

  • *
  • Posts: 2810
Here's how to do it. I don't know if you actually need this, or it's just a suggestion for the future, but here it is nonetheless.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.

Sunflower

  • Posts: 591
Hooray! That means that my finding index system is probably correct! (yes, we have everything except arguments names the same; but thanks, anyway ^^)

But yes, as coleislazy said, it's strange that there isn't built-in block for that. And it's even more strange that there's block which requires using this functionality ("remove [item] from [ list ]", to be more precise).
Oh, and since it was mentioned, multi-dimensional arrays system would be nice, too. O.o

Sunflower

  • Posts: 591
...uh, so, what about adding such built-in block? O.o' Not only it doesn't seem difficult to include (indexOf in AS3, probably something equally easy in iOS and others), but it'd be pretty useful too! ^^'

(and it'd make the Custom Blocks section of mine less cluttered >.<)