Comparing array indexes with the animation frame

0 favourites
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • I am randomising 10 numbers (1-10) in a array and I need to compare some of these numbers with the animation frames of the some sprites. This amount is changing during the game (1st time = 3 numbers / 2nd = 5 numbers / ...)

    My code:

    Function

    Array For each X element

    Array value at 0 = Sprite1.animationFrame (action)

    Else (action)

    But it's not working . What am I doing wrong?

  • Array.CurValue = Sprite1.animationFrame

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Array.CurValue = Sprite1.animationFrame

    Hey blackhornet

    But if my array have 10 values how can I know the current value?

    Sometimes I will need to compare 3 numbers, so it's wrong:

    Array value at 0 = Sprite1.animationFrame (action)

    Array value at 1 = Sprite2.animationFrame (action)

    Array value at 2 = Sprite3.animationFrame (action)

  • But you are doing For each element, which is running through the array for you, setting the current index value to CurValue.

  • So I can do:

    Array Current value = Sprite1.animationFrame (action)

    Array Current value = Sprite2.animationFrame (action)

    Array Current value = Sprite3.animationFrame (action)

    But if I not use the "for each element"? if I need to set a frame using an array value? Can I do that:

    Sprite3 Set animation frame to Array.At(5)

    If so, I don't know why it's not working too.

  • You are mixing up the two array mechanisms. The Array object has it's own expressions for looping through the array, or you can use system events. It would be better to post a CAPX, as it's not clear what you really want to do.

  • I juts want to check if the array value is the same of the sprite animation frame (comparing the frame of one or three sprites at the same time) and I want to show the animation frame according with the array value (anyone that I want to show).

  • http://www.blackhornettechnologies.com/Construct2Stuff/ArrayToFrame.capx

    There's different ways of doing this. Here's one.

  • Hey blackhornet

    Thanks for the example. It's similar that I am doing here. The only difference is that I am using a function to check if the array values are equal or not to the animation frames. Seems that the loop stops in the first value.

    Function On "check"

    For "" from 0 to 9

    Array Value at loopindex = Sprite1.AnimationFrame (action)

    Array Value at loopindex = Sprite2.AnimationFrame (action)

    Array Value at loopindex = Sprite3.AnimationFrame (action)

  • Again, you need to post what you have. A function should make no difference.

  • Again, you need to post what you have. A function should make no difference.

    Ok. Here it goes.

    [quote:28d1tk34]https://www.dropbox.com/s/5xshuvuyp6q6ngw/test.capx?dl=0

    The checking system is not working and it's also not recognising the number 10.

  • You can't use Trigger once that way. What is "check" supposed to do? I know you are comparing the array to the frame, but what are you looking for - use a specific example please.

  • Sorry, I thought it was clear. Check if the sequence is right. If each frame is right it will add 1 to the "hit" if the player got 3 hits, something happens.

  • Please be specific. Right now the code looks to see if any number in the array matches, which makes no sense. That's why you need to be specific. Do they need to match from index 0,1,2, or match the sequence anywhere in the array? Very different code.

  • Please be specific. Right now the code looks to see if any number in the array matches, which makes no sense. That's why you need to be specific. Do they need to match from index 0,1,2, or match the sequence anywhere in the array? Very different code.

    Always the sequence of the array (Index 0,1,2,3,4,...).

    On the left of the screen you can generate the random numbers and when you click in "show" the game show you the sequence (the first three numbers of the array). I will use 3 number at the beginning and I will increase this amount during the game.

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