Comparing array indexes with the animation frame

Get help using Construct 2

Post » Sun Dec 04, 2016 6:31 pm

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?
B
4
S
2
Posts: 123
Reputation: 846

Post » Sun Dec 04, 2016 6:34 pm

Array.CurValue = Sprite1.animationFrame
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Dec 04, 2016 6:38 pm

blackhornet wrote: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)
Last edited by Braus on Sun Dec 04, 2016 7:17 pm, edited 2 times in total.
B
4
S
2
Posts: 123
Reputation: 846

Post » Sun Dec 04, 2016 7:15 pm

But you are doing For each element, which is running through the array for you, setting the current index value to CurValue.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Dec 04, 2016 7:17 pm

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.
B
4
S
2
Posts: 123
Reputation: 846

Post » Sun Dec 04, 2016 7:35 pm

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.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Dec 04, 2016 7:48 pm

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).
B
4
S
2
Posts: 123
Reputation: 846

Post » Mon Dec 05, 2016 6:20 am

http://www.blackhornettechnologies.com/Construct2Stuff/ArrayToFrame.capx
There's different ways of doing this. Here's one.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Mon Dec 05, 2016 11:08 am

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)
B
4
S
2
Posts: 123
Reputation: 846

Post » Mon Dec 05, 2016 3:41 pm

Again, you need to post what you have. A function should make no difference.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Next

Return to How do I....?

Who is online

Users browsing this forum: ketramtu18, MaujDeveloper and 9 guests