Logic Problem?

For questions about using Classic.

Post » Mon Oct 18, 2010 3:36 am

So I'm making a game where you have a rock shooting cannon and you hit birds with rocks.

-Once a rock hits a bird, it's physics are enabled and it falls

-Once a bird hits a bird, it's physics are also enabled which will be what triggers combos

-The birds fly across the screen at random Y locations

Problem:
Before I hit a bird with a rock and 2 birds collide, they will both fall. I only want a bird to effect another bird after it has been hit with a rock.

I've tried fixing this by giving a private variable to a bird, making it true once a rock hits it, and checks if the bird is being hit by another bird with the property as true, but to check a private variable of an object only checks it's own private variable, not the private variable of another object.

I hope that makes sense, I'm really lost here. I'll upload the .cap if anyone needs it.
B
2
G
2
Posts: 19
Reputation: 688

Post » Mon Oct 18, 2010 4:10 am

Post the cap chap and I will take a look.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Oct 18, 2010 4:23 am

http://www.mediafire.com/?gitp6ab339lp4uo
Here you go. Good luck. I tried to redo it but got the same results.
B
2
G
2
Posts: 19
Reputation: 688

Post » Mon Oct 18, 2010 5:19 am

http://dl.dropbox.com/u/1487524/Scirra/Birds.cap

here you go. I have added comments as to what was going on.

I would also recommend you investigate the physics behaviour some more, particularly the gravity and ways to toggle that off and on when the birds get hit.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Oct 18, 2010 2:12 pm

Steven solved the logic problem nicely with the check for being 'active', but on my machine, there is a different problem that remains:

+ Sprite2: On collision between Sprite2 and Sprite2

That causes somewhat random crashes on my machine. Construct has no good way to differentiate between the two different instances of Sprite2 there, and it seems to cause problems.

In the event that you've not had to deal with such a problem before, I'll discuss a common way to deal with it.

The easy way to deal with needing to pick two different instances of the same object in the same event is to add that object into a family (let us use Blue family.) Here, if a Sprite2 is 'active' and has collided with any other Sprite2, the other Sprite2 is also set to 'active':

+ Sprite2: Value 'active' Equal to 1
+ Sprite2: On collision between Sprite2 and Blue
-> Blue: Set 'active' to 1

In this way, any actions performed upon Sprite2 within that event will only affect Sprite2 objects that have the 'active' var set and have collided with a Blue family member (which only contains Sprite2 objects here.) Any actions performed upon Blue in that event will only affect the Blue member that was collided with by the aforementioned Sprite2 object.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Mon Oct 18, 2010 6:47 pm

Silent Cacophony - I also had a few crashes during the collisions. I will keep that little work around in mind if I run into things like that in my project.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Mon Oct 18, 2010 10:12 pm

[quote="Steven":306w9p5n]http://dl.dropbox.com/u/1487524/Scirra/Birds.cap

here you go. I have added comments as to what was going on.

I would also recommend you investigate the physics behaviour some more, particularly the gravity and ways to toggle that off and on when the birds get hit.[/quote:306w9p5n]
Awesome, other than the crashing, it works great, thanks man. :D

[quote="Silent Cacophony":306w9p5n]
+ Sprite2: Value 'active' Equal to 1
+ Sprite2: On collision between Sprite2 and Blue
-> Blue: Set 'active' to 1
[/quote:306w9p5n]
This also got rid of the crashing. It's perfect now and I'll definitely use this method in the future.

The core of the game is pretty much finished now thanks to you guys. I have a few features to add and it'll be done. Yay!
B
2
G
2
Posts: 19
Reputation: 688


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests