Delay probs

For questions about using Classic.

Post » Fri Nov 26, 2010 8:01 pm

I'm sure everybody already encountered the following problem, but I am the one who has never been able to figure out what to do.

If, for example, I want a brick (in a brick breaker game) to change from animation 1 to animation 2 when it's hit by the ball once. Then, when the ball hits the brick again, I want the brick to change from animation 2 to animation 3. And so on.
But, there's no delay or anything, so the brick changes from the first animation to the last animation when it's hit once. VERY annoying.

And then, when I'm just about to go see my psychologist, the Construct devs release a new version with the so cool wait object!

...But even with it, I still have problems. Depending where I put the "wait for 10 ms" condition/action, I got either all the instances of a same object to be affected when one of them is hit, either the same problem which leads the brick to go to its very final phase when it's hit only one time.
CAP file (problem located in the events of the ''Hit Bricks'' group) : http://butor.com/resource.do?uid=1292198866697

Please help me...
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Fri Nov 26, 2010 9:52 pm

Salut !

It will work if you reverse the order of the events.
i removed the wait object and rearranged the events like this instead :

[code:3umkpfdo]
+ Balle: On collision between Balle and BricBrique
+ BricBrique: Pick closest to: Balle.X, Balle.Y
+ BricBrique: Animation "5" is playing
-> System: Add 1 to global variable 'briques'
-> BricBrique: Destroy
+ BricBrique: Animation "4" is playing
-> BricBrique: Set animation to "5"
+ BricBrique: Animation "3" is playing
-> BricBrique: Set animation to "4"
+ BricBrique: Animation "2" is playing
-> BricBrique: Set animation to "3"
+ BricBrique: Animation "1" is playing
-> BricBrique: Set animation to "2"
+ BricBrique: Animation "0" is playing
-> BricBrique: Set animation to "1"
[/code:3umkpfdo]

Indented "+" events are sub-events.

it seemes to work ok... edit : but someone may know a better way (surely, i ain't a programmer lol)
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Sat Nov 27, 2010 2:35 pm

Erm, i noticed a bit late that your animations used numbers as names.... :?
So you can just set a private variable (hitme = 0) and increment it :

[code:1dkfn2fp]
+ Balle: On collision between Balle and BricBrique
+ BricBrique: Pick closest to: Balle.X, Balle.Y
+ BricBrique: Value 'hitme' Less or equal 5
-> BricBrique: Add 1 to 'hitme'
-> BricBrique: Set animation to BricBrique.Value('hitme')
+ System: Else
+ BricBrique: Value 'hitme' Greater than 5
-> System: Add 1 to global variable 'briques'
-> BricBrique: Destroy[/code:1dkfn2fp]


And probably you could use families too, that could save you a lot of events...
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Sun Nov 28, 2010 8:11 pm

Hey, toi aussi t'es francophone? :-D

'Til now it works! Thanks a bunch!
...I didn't know 'pick closest' condition... :oops:

Though, I don't see how I could use families. Since there are three kinds of brick, and that each of them is destroyed after a different number of hits, I think it'd be hard to get family events to work properly. :-/
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Mon Nov 29, 2010 7:54 am

[quote:29r6cd7w]Hey, toi aussi t'es francophone? :-D[/quote:29r6cd7w]

De la tte aux pieds! :wink:

[quote:29r6cd7w]'Til now it works! Thanks a bunch!
...I didn't know 'pick closest' condition... :oops: [/quote:29r6cd7w]

Heh, that's cool :) You got a hell lot of events in there, though !
And it wasn't working because, you wrote them in order '1,2,3...", and from what i've read around here, events are executed one after the other. In your case, 0 was true, so you switch animation to 1. But then the next event (animation is 1) is true too, so it switches to anim 2, and so on... I've seen a similar case around the forums here :) So all you have to do is reverse the events...

[quote:29r6cd7w]Though, I don't see how I could use families. Since there are three kinds of brick, and that each of them is destroyed after a different number of hits, I think it'd be hard to get family events to work properly. :-/[/quote:29r6cd7w]

Actually, i don't know either :roll: Haven't tried it in your game. It's probably OK the way it is now, as long as it works, it's ok I guess XD
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Mon Nov 29, 2010 10:26 pm

C'est quand mme drle de penser qu'on parle toujours en anglais pour tre srs que les autres comprennent! :-D

The events order things is weird, but anyway, if it works I won't complain. :-)

Thank you for helping!
B
11
S
3
G
3
Posts: 206
Reputation: 2,379

Post » Tue Nov 30, 2010 11:48 am

Je pense que c'est normal.

If everyone here were writing in their native tongue, how could we help each other out?

[quote:202yr8mi]
The events order things is weird, but anyway, if it works I won't complain.[/quote:202yr8mi]

It's true it appears more logical to put them in numerical order. But then, like i said, all conditions will be true, one after the other. But on screen, you will only see the last result : the brick disappears, because all actions are performed ultra fast. Like superman reading a book xD

[quote:202yr8mi]Thank you for helping![/quote:202yr8mi]

NP, it helps me to learn Construct too :)
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Tue Nov 30, 2010 1:17 pm

[quote="Kan":3vmp428i]The events order things is weird, but anyway, if it works I won't complain. :-)[/quote:3vmp428i]
Je comprend si tu parle en francais, mais stell dir mal vor ich wrde die ganze Zeit deutsch reden :wink:

To understand what really happens, and why the event order is so important, you may want to have a look at this thread: Introduction to branching

Another way to do it without reversing the order is using "else" (see the thread above)

[code:3vmp428i]+ BricBrique: Animation "0" is playing
-> BricBrique: Set animation to "1"
+ Else
+ BricBrique: Animation "1" is playing
-> BricBrique: Set animation to "2"
+ Else
+ BricBrique: Animation "2" is playing
-> BricBrique: Set animation to "3"
...
etc
[/code:3vmp428i]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Nov 30, 2010 3:11 pm

[quote:35qgu5o8]stell dir mal vor ich wrde die ganze Zeit deutsch reden[/quote:35qgu5o8]

Essayez d'imaginer si je parlais allemand tout le temps :)


Thanks Google hehe :)

I used Else here too :

[code:35qgu5o8] + Balle: On collision between Balle and BricBrique
+ BricBrique: Pick closest to: Balle.X, Balle.Y
+ BricBrique: Value 'hitme' Less or equal 5
-> BricBrique: Add 1 to 'hitme'
-> BricBrique: Set animation to BricBrique.Value('hitme')
+ System: Else
+ BricBrique: Value 'hitme' Greater than 5 <== EDIT : i think this line can be removed
-> System: Add 1 to global variable 'briques'
-> BricBrique: Destroy[/code:35qgu5o8]

Anything wrong with it? I just wanna know if i can improve this. I like to keep the code very short, if possible.
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

Post » Tue Nov 30, 2010 8:23 pm

[quote="prawnsushi":3adycjmx]I used Else here too :

[code:3adycjmx] + Balle: On collision between Balle and BricBrique
+ BricBrique: Pick closest to: Balle.X, Balle.Y
+ BricBrique: Value 'hitme' Less or equal 5
-> BricBrique: Add 1 to 'hitme'
-> BricBrique: Set animation to BricBrique.Value('hitme')
+ System: Else
+ BricBrique: Value 'hitme' Greater than 5 <== EDIT : i think this line can be removed
-> System: Add 1 to global variable 'briques'
-> BricBrique: Destroy[/code:3adycjmx]

Anything wrong with it? I just wanna know if i can improve this. I like to keep the code very short, if possible.[/quote:3adycjmx]
Oh, I'm sorry, I overread this. You are right with your edit. That line can be removed. Nice improvement of the code :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests