suggest: system expression tokenIndexOf

0 favourites
  • 8 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • The existing system expression tokenAt(list,index,delimiter) will yield which token is at the specified index.

    tokenIndexOf would do the opposite, that is, tokenIndexOf(list,query,delimiter) will yield the index of the specified query token or -1 if it is not in the list.

  • So it's like a search through the tokens? Would tokenIndexOf("foo,foo,foo", "foo", ",") return 0, 1 or 2?

    It sounds useful but I don't really want to end up implementing a full parser engine in system expressions! :)

  • lets have it return the first index found!

  • Implementation of indexOf is rather simple, since javascript already has a .indexOf array function, which gives the index of first occurrence of the given element. I've already provided an implementation in my Extra Expressions plugin as an expression (findToken). It was so simple I added case sensitivity mode for extra challenge!

    There's also .lastIndexOf(), which returns the index of last matching element.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • How about just doing a naive delimited-list search returning the index of the first element matched? Being able to search the list imho is kind of important and would be better than using find(sep&list&sep,needle) as a kludge which doesn't yield a proper index.

  • Mipey

    Thanks for adding it to your plugin btw. :)

    The only problem with having it in a plugin is the obvious problem that games intended for the arcade can't make use of it.

  • It would be nice to have more support for strings. Array's are nice but for smaller games and projects having the ability to read strings as lists would be rather handy indeed. If I'm not mistaken it would allow more thorough searches IE: this:isn't:cool searching o brings up cool when that's not the case lol.

    Wouldn't this also improve performance by not needing to rely on arrays as much saving ram etc for smaller devices like some of the first gen smart/superphones?

    I'm not quite sure how a parsing engine would be necessary for something that's easy enough to do with string.split, then search from the start until a match is found or the list is exhausted? I'm no expert more of an inquiry, It's just something that you would think would be in a good practices to have.(More string support that is. The section in the documentation is pretty bare)

    Just my 2cents.

  • Om3n: I'm not sure to follow your whole idea/request, but for string handling you have several system expressions (like in your example sting.split is tokenat(src, index, separator))

    It works with any string (coming from an array, a variable, a text object, or anything), was this what you were asking for ?

    There are also several other custom plugins to help with such operations/stock but as Gauveldt noted, it's not the best solution if, for now, you're aiming to upload your game to Scirra's arcade.

    Hopefuly it is just a temporary drawback.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)