Trying to Make a Loop but Not Working

For questions about using Classic.

Post » Sun Feb 05, 2012 9:21 pm

I am trying to make a simple (being retro style) shield system in my space shooter. Trying to make it that while the Hero's 2nd animation is running, a timer of Xms will eventually put the ship back to animation 1. However, all I can get it to do is come on at some point after the "BookCount" trigger has already passed one or two times. Here is the text copy of the four-step event:

(event 70)
+ Hero: On collision between Hero and BibleDrop
-> System: Add 1 to global variable 'BookCount'
-> BibleDrop: Destroy

(event 71)
+ System: Is global variable 'BookCount' Equal to 66
-> System: Add 2000 to global variable 'Score'
-> System: Set global variable 'BookCount' to 0
-> Hero: Set animation frame to 2

(event 72)
+ Hero: Animation frame Equal to 2

(event 73)
+ System: Every 5000 milliseconds
-> Hero: Set animation frame to 1

However, just can not get that second animation to run after the 66 BookCount, for Xms. Once I can get this working, I can then move on to what the shields should be doing.

Thanks for any help on this.GSPforChrist2012-02-06 20:29:09
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Feb 08, 2012 2:43 am

I might have this a bit wrong, thinking how loops work in C++ than in here. I was reading in the wiki and think it might be best if I remove event 72 and 73. Is there a way to make it check if the Hero's 2nd animation is running after Xms, then switch back to the 1st animation? Something like:

If Hero animation 2 is running for 30000ms, then switch back to animation 1.

Thanks.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Feb 08, 2012 3:53 am

Is (Event 73) a Sub-Event of (Event 72), or one of the Main Events?
If it's a Main Event, then that's Your problem.Shindoh2012-02-08 03:53:51
B
3
G
1
Posts: 70
Reputation: 615

Post » Wed Feb 08, 2012 3:53 am

Just make something like:
+ Hero: animation is 2
-> Add 1 to variable "heroShield"

+ Variable "heroShield" >= 3000
-> Set "heroShield" to 0
-> Hero: set animation 1
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Wed Feb 08, 2012 5:11 am

Shindoh, they were all sub-events of one another.
70
.71
..72
...73
Now I just have...
70
.71

7Soul, I see what you mean. I was thinking more complicated. Thinking something like Hero.Animation1 jazz had to be done, and that was confusing me. I did not think I could go simple like that. I will give your idea a try.

Thanks, all.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Wed Feb 08, 2012 12:57 pm

[QUOTE=GSPforChrist]
(event 70)
+ Hero: On collision between Hero and BibleDrop
-> System: Add 1 to global variable 'BookCount'
-> BibleDrop: Destroy

(event 71)
+ System: Is global variable 'BookCount' Equal to 66
-> System: Add 2000 to global variable 'Score'
-> System: Set global variable 'BookCount' to 0
-> Hero: Set animation frame to 2

(event 72)
+ Hero: Animation frame Equal to 2

(event 73)
+ System: Every 5000 milliseconds
-> Hero: Set animation frame to 1
[/QUOTE]
Okay, according to my logic what should happen with this is:
When 'BookCount' is 66 the animation frame will be changed to 2. (note animation frame is not another animation, but the second frame of the current animation)
Then in Event 73, Every 5 seconds, we set animation frame to 1. (note again, not the animation, but the frame of the current animation)

What we should see with this code, is the animation "frame" changing to the second frame one time, once 'BookCount' is 66, and then never change back to frame 1.
Because Event 73 is only run every time if in the same frame/tick: "Hero Collides with BibleDrop AND BookCount = 66 AND Hero Animation Frame = 2. However in the next tick, the Event check already can't get down to Event 73, because Hero must still be colliding with Bible Drop and BookCount must be equal to 66.

From my understanding, You should better use the Every X ms as a main Event, combined with a constantly true condition (or at least true for longer than the 'Every X ms' You entered), like a variable.

7Souls way is a good suggestion.
Shindoh2012-02-08 13:00:52
B
3
G
1
Posts: 70
Reputation: 615

Post » Mon Feb 27, 2012 12:46 am

This is what I have now...

21

+ Hero: Value 'Shields' Equal to 0
-> Hero: Set animation frame to 1

22

+ Hero: Value 'Shields' Equal to 1
-> Hero: Set animation frame to 2

74

+ Hero: On collision between Hero and BibleDrop
-> System: Add 1 to global variable 'BookCount'
-> BibleDrop: Destroy

75 (sub event of 74)

+ System: Is global variable 'BookCount' Equal to 66
-> System: Add 2000 to global variable 'Score'
-> System: Set global variable 'BookCount' to 0
-> Hero: Add 1 to 'Shields'

And this is what I have tried with more success than anything else...

23 (sub event of 22)

+ Hero: Animation frame Equal to 2

24 (sub event of 23)

+ System: Every 1000000 milliseconds
-> Hero: Set 'Shields' to 0

I have gone this high in timing (1000000 milliseconds), but the result is always the same. The "shield" (frame 2) will flash for a split second at the first 66 BookCount mark. The second time the 66 book count comes around, frame 2 stays on and never changes back.

The idea is to have it that the shields last for, say 30 seconds. With the shields on, I will have it that the ship is, of course, invulnerable to weapon fire, but not collisions. Not sure how to deal with this yet, as I usually stick with one problem at a time.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Mon Feb 27, 2012 1:24 am

if you make a simple capx and post here I can help you ^~

I was having troubles with looping, but one day a light illuminated my brain and I saw the mechanic behind C2, so, I think everything is possible now, lol...

See you.
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Mon Feb 27, 2012 4:32 am

I put up a current copy of it, stripped of about everything else, to show the current setup for the shield method I am trying to do.

http://www.mediafire.com/?lgdka53y2fjv222

I have the book drop at a rate so I could collect and then time the shields.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Post » Mon Feb 27, 2012 12:34 pm

There are two things I see up front.

The first is, You add 1 to the 'Shields' variable, instead of setting it to 1, when 'Bookcount' = 66. And You only set the Frame to 2, if 'Shields' = 1.
Why is this a problem? Well, if we think ahead. Then what will happen, if 'Shields' = 2? Which will happen, because You always add 1 to 'Shields' for each 66 Bookcounts. Of course right now nothing will happen if it's 2, but You never set back 'Shields' = 0.
And You say if 'Shields' = 0 -> Set Frame to 1.
Also the Sub-Event code for "Every 15000ms" will only run, if 'Shields' = 1.

The next things is, the short flash You see. Why? Think about it again. When do You set Frame = 1? If 'Shields' = 1 AND "Every 15000ms".
So this Tick let's assume 'Shields' = 1 AND "15000ms" have passed in this Tick. In this Tick Frame will be set back to 1. However the next Tick the 'Shields' = 1 Event will be checked again and what happens if 'Shields' = 1? Set Frame 2.

It can be maddeningly frustrating at times, but stick to it and with time You will get the hang of it. You know, every beginning is hard and all good things take time. It's also important to keep a cool head and try to keep a good overview and memory in Your head of the processes going on at all times, that might be related to other.
B
3
G
1
Posts: 70
Reputation: 615

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests