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

  • 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...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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...<img src="https://dl.dropboxusercontent.com/u/39000273/Index.png" border="0" />

  • "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.

  • 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!

  • <img src="https://dl.dropboxusercontent.com/u/39000273/Index2.png" border="0" />

    Fixed!! Thanks a lot for both solutions! My project is working much much better now.

  • You should have 0 to Width-1. IE: For an array with width of 10, the indices are 0 to 9!

  • 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!

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