Compare Frames

Get help using Construct 2

Post » Sun Aug 04, 2013 10:14 pm

I can't get the compare frame event to work, I have a sprite that spawns two instances of a new sprite every 3 seconds and I'd like it to compare the two new instance's frames to check if they are the same. if so, change it

capx file

http://www.fileswap.com/dl/lEagoxlFE/

Alternatively I'd like to know how this would be best accomplished using families just for my own sake because I've tried it with them as well to no availCentra2013-08-04 22:17:10
B
10
S
2
Posts: 76
Reputation: 987

Post » Mon Aug 05, 2013 1:41 am

people aren't as helpful as they used to be
B
10
S
2
Posts: 76
Reputation: 987

Post » Mon Aug 05, 2013 1:58 am

I feel the same way.

The truth at the end of the day is that nobody cares about your project except for you. This is why every single one of my 'how do I?' threads involves me posting follow-ups stating things I've found as I've tried to diagnose the problem. People probably won't read them, but what drives me to develop is the notion of progress, even if it's just a little progress, and that's why I continue to post.

Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,224

Post » Mon Aug 05, 2013 2:05 am

Posting your findings does help others who are following in your footsteps, i know it's helped me in a number of unresolved posts when people post their findings even if its not solved at least there's a little more info to go on.

Shame though, I thought the community was more active.
B
10
S
2
Posts: 76
Reputation: 987

Post » Mon Aug 05, 2013 3:17 am

@Centra
The two issues you are running into are newly created object picking and dealing with picking multiple instances of the same type separately.

Created objects become the only picked object for the the rest of the event. In the case of event 1 and 2 the 2nd spawned sprite will always have "isanswer" toggled. Also the created object object won't be able to be picked as normal until the next toplevel event (event that isn't a subevent) however a triggered event such as "on created" or a funtion call doesn't count as it's more like it's run right when it's called. Your on created event as it is has only one sprite picked (the new one) which can be somewhat solved by adding a "pick all sprite" system event, but you still won't be able to pick the other spawned sprite until the next toplevel event.

And that leads nicely into issue #2, picking multiple instances of the same type separately. There are two ways to deal with this:
* The first way is to pick one of the instances and save the values you want to compare into local variables and then pick the 2nd and do the comparison. It would look something like this:
[code]+ Some event that picks two sprites
---local number inst0frame=0
---+pick sprite instance 0
------ set inst0frame to sprite.frame
---+pick sprite instance 1
---+compare inst0frame = sprite.frame
------ do something[/code]

* The second way is to use single object type family. So you can pick two objects of the same type separately using two different names. You can think of the family name as an alias to the object name. Events would look something like this:
[code]+ Some event that picks two sprites
---+pick family1 with uid of sprite.uid
---+pick family1 instance 0
---+pick sprite instance 1
---+compare family1.frame = sprite.frame
------ do something[/code]

Ok, and in respect to what you're trying to do you can simplify it by putting the sprite into a family and call it say family1.
[code] +every 3 seconds
---create sprite
---set sprite frame to random
---create family1
---set family1 frame to random
--- +while
--- +compare sprite.frame = family1.frame
-------set family1 frame to random[/code]

cheers
B
85
S
27
G
85
Posts: 5,063
Reputation: 57,860

Post » Mon Aug 05, 2013 6:24 am

Thank you very much, I appreciate you going the extra mile to explain how picking instances are handled. Following your example at the end, still giving me problems though.

Centra2013-08-05 18:20:00
B
10
S
2
Posts: 76
Reputation: 987

Post » Mon Aug 05, 2013 7:14 am



this one doesn't give a runtime error but it doesn't prevent duplicates eitherCentra2013-08-05 07:28:35
B
10
S
2
Posts: 76
Reputation: 987

Post » Mon Aug 05, 2013 6:04 pm

My main problem seems to be 'some event that picks two sprites'
B
10
S
2
Posts: 76
Reputation: 987

Post » Tue Aug 06, 2013 1:16 am



Finally got it to run without duplicates, debugging display for frames doesn't work thoughCentra2013-08-06 03:19:04
B
10
S
2
Posts: 76
Reputation: 987


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests