How do I return the iid of an array value.

Get help using Construct 2

Post » Sun Jun 14, 2015 3:00 pm

What is the expression to return the iid value of an array value?
example.

Player just scores 432 in a game, which is saved into an array, by Ajax.lastdata in ascending order.

0 ... 567
1 ... 432
2 ... 98

I would like to return the iid of value 432
I can then use, array.at(1), to display it to text as a basic ranking system

cheers
Last edited by sizcoz on Sun Jun 14, 2015 3:21 pm, edited 1 time in total.
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sun Jun 14, 2015 3:09 pm

You can use 'IndexOf' to get the index of the value. There are no IIDs for values.

https://www.scirra.com/manual/108/array
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sun Jun 14, 2015 3:14 pm

I have tried this but I must be going wrong somewhere, reports -1

array.indexof(432)

returns -1

cheers
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sun Jun 14, 2015 3:27 pm

http://www.blackhornettechnologies.com/ ... dexOf.capx

Edit: you can use the Debugger to inspect the array.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sun Jun 14, 2015 4:16 pm

Ok this only works if I manually set the array value like you did in your capx
It does not work if i set the values in the array with tokenat(Ajax.LastData,array.CurX, "|") from my database with a for each x element.
The Array shows all the values and indexes on the debugger but I cant reference them with indexof, unless I manually set them, which defeats the object.

any ideas?

cheers
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sun Jun 14, 2015 4:49 pm

Coming from Ajax, the values will be strings. Either convert them to ints, or use a string to search: IndexOf("432")
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sun Jun 14, 2015 4:55 pm

Ok thats brilliant.

solved

cheers
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sun Jun 14, 2015 5:13 pm

Ok for future reference I was using a global variable so I had to convert the integer into a string with str

array.IndexOf(str(Global variable here))

Many thanks for your help
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests