suggest: system expression tokenIndexOf

Discussion and feedback on Construct 2

Post » Thu Jan 12, 2012 2:05 am


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.GauVeldt2012-01-12 02:06:21
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Thu Jan 12, 2012 11:25 am

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! :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Thu Jan 12, 2012 1:46 pm

lets have it return the first index found!
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Thu Jan 12, 2012 1:52 pm

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.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Jan 12, 2012 3:57 pm

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.
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Thu Jan 19, 2012 5:50 pm

@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.GauVeldt2012-01-19 17:51:27
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Thu Jan 19, 2012 6:30 pm

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.

B
5
G
2
Posts: 18
Reputation: 1,286

Post » Thu Jan 19, 2012 9:10 pm

@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.Kyatric2012-01-19 21:11:16
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 15 guests