array.IndexOf(first.value.only) ?? left("",1)

Get help using Construct 2

Post » Mon Aug 19, 2013 1:11 am

How would I return an IndexOf trying to match only the first value per cell?

I am hoping to organize like this:

11
12
13
21
22
23
31
32
41
42
43
44

The first number is the Act, second number the Scene...

I've been trying to use Left(,) but I can't get it to work.

To pull Act 2 I've tried:

left(array.IndexOf(int((2),1))
doesn't seem right.

array.IndexOf(left(2),1))
also doesn't seem to work.

I know I could bubble-process this but it seems there should be an easier way to write this.

Currently I am doing this:

OnTouch:
array.ForEachX:
     If: left(array.At(array.CurX), 1)) = 1 then StopLoop and DoThis
     If: left(array.At(array.CurX), 1)) = 2 then StopLoop and DoThis

etc, etc... Maybe this is the best way to do this? Except that its not really working either. I am getting the last value that matches not the first...goblynn932013-08-19 01:38:59
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Mon Aug 19, 2013 1:41 am

To find the first index of act 2, would be IndexOf(act*10+1). So for act=2, IndexOf(2*10+1), which is IndexOf(21). IndexOf(31)-1 would be the last act 2 index.
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Mon Aug 19, 2013 2:10 am

Well that makes perfect sense... and totally fixes that issue... But I can't do the same thing to my other array with text...



I am getting the last value of A names, not the first...goblynn932013-08-19 02:10:57
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Mon Aug 19, 2013 2:44 am

"Stop loop" is a System action, not an Array action! It won't work. I vaguely remember someone requesting an "Array.Stop loop" action. Use the System.For mechanism instead, to index into the Array.
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Mon Aug 19, 2013 2:47 am

Hmmm OK I think I can work that out... makes sense that the Loop Stop is system and has no effect on the array action. Array.StopLoop would be nice!

Thanks for taking a look!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Mon Aug 19, 2013 2:56 am


Fixed!! Thanks a lot for both solutions! My project is working much much better now.
B
10
S
4
G
2
Posts: 133
Reputation: 2,667

Post » Mon Aug 19, 2013 2:59 am

You should have 0 to Width-1. IE: For an array with width of 10, the indices are 0 to 9!
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Mon Aug 19, 2013 3:04 am

Thanks for catching that! It would have been obvious once I put this through its full test but now I won't have to face-palm later!
B
10
S
4
G
2
Posts: 133
Reputation: 2,667


Return to How do I....?

Who is online

Users browsing this forum: rayolf and 22 guests