Help doing something else if conditions aren't met?

For questions about using Classic.

Post » Tue Jun 23, 2009 12:54 am

I'm gonna try and explain this best I can...

I'm making my own little tweaks to Ghost Shooter. I have a 7 frame sprite, called Bullet Count, that keeps track of ammo. Frame 7 of the animation depicts 6 bullets, 6th frame depicts 5 bullets, etc., down to the 1st frame showing no bullets at all. I also give Bullet Count the private variable, "Frame Number" and set Bullet Count's frame number equal to this variable. When the layout starts, Frame Number is set to 7 (thus making the Bullet Count's animation set to frame 7). When the left mouse button is clicked, a bullet is fired and 1 is subtracted from Frame Number, as long as Frame Number is greater than 1 (again, this would correspond to frame 1 of Bullet Count, which depicts no bullets).

Now, what I want to do is if the conditions aren't met - that is, Frame Number is equal to 1 and the player left clicks - to instead play a "click" sound, as if the gun were empty. I tried using the "else" event, but I couldn't get it to work correctly.

Any idea how I can achieve my goal?
B
2
G
3
Posts: 12
Reputation: 874

Post » Tue Jun 23, 2009 1:06 am

you should add else as new event, not new condition.

notice the gap in first event? thats how it should look like



alternatively you could just check if your variable is "Less or equal" to 1 and play the sound there.
B
24
S
7
G
3
Posts: 138
Reputation: 2,795

Post » Tue Jun 23, 2009 5:07 pm

Well, I wasn't using Else as a condition, I was using it as an event, like you said.

This doesn't work:


I guess since the first half isn't testing anything, such as 0 is between 6 in 7, the else event doesn't work.

I also tried these:





Of course, both had the same results...just not the ones I was looking for! In both cases, the sound (In the image it's Monster Scream2, but that's just filler for the "click" sound) played when the last bullet was fired, NOT when the mouse was clicked after the last bullet. :?
B
2
G
3
Posts: 12
Reputation: 874

Post » Tue Jun 23, 2009 5:37 pm

[quote="Mr. Bucket":12oqotnz]This doesn't work:
[/quote:12oqotnz]
'Else' doesn't work after a triggered event (one with a green arrow, like 'on mouse button clicked'). Since triggered events fire when an event happens, such as when a button is clicked, and can happen at any point in time, what would 'else' after that mean? Trigger at all points in time that event is not happening? It wouldn't make sense, so that's why 'else' doesn't work where you put it.

If the other conditions were subevents to the trigger, it could work - 'else' can follow the non-trigger subevents.

[quote="Mr. Bucket":12oqotnz][/quote:12oqotnz]
This one should work: if you left click or double click and you are out of ammo, play a sound. Are you sure it didn't work? Maybe post a .cap of this one. How many 'bulletcount' objects do you have? You should only have one, or the event picking will keep individual counts for each object.

[quote="Mr. Bucket":12oqotnz][/quote:12oqotnz]
Subevents are only tested if the parent event conditions were met - so you've made this one a logical impossibility. First check if 'Frame Number' is greater than 1, and if it is, then check if it is equal to 1, which it can't possibly be ;)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Jun 23, 2009 5:59 pm

Ah, I see now about the else event. I was trying to get Else to work as "If the conditions aren't met" kind of thing.

I agree that the second one should work, and the third thing I tried was just a move of desperation. :P

Here's a .cap of the 2nd one.

[url:euwso9fn]http://www.quickfilepost.com/download.do?get=90e1f000de76dc95b9600e75baa46596[/url:euwso9fn]

It's worth mentioning that the sound does indeed play after there's no bullets and you click, I just don't want it doing it when the last bullet is fired.

Feel free to point out any other things in my event sheet that don't seem right. ^_^

PS- Didn't wanna make a whole new thread for this...how can I make an object do something when an instance of it is created? I didn't see any event for that. (I'm trying to make it so that when you shoot an enemy, when the explosion is created, the explosion is set to a random angle. That way, the explosions become a little less tedious.)
B
2
G
3
Posts: 12
Reputation: 874

Post » Tue Jun 23, 2009 6:39 pm

[quote="Mr. Bucket":2l62emm6]It's worth mentioning that the sound does indeed play after there's no bullets and you click, I just don't want it doing it when the last bullet is fired.[/quote:2l62emm6]
Then compare it to 0, not 1 :P

[quote:2l62emm6]how can I make an object do something when an instance of it is created?[/quote:2l62emm6]
Follow it by an action. Eg.:
-> Create object 'Explosion'
-> Set 'Explosion' angle to random(360)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Jun 23, 2009 6:57 pm

Frame Number can never reach zero! Because to Fire (and therefore reduce Frame Number by 1), Frame Number must be greater than 1. Plus, Frame Number corresponds to Bullet Count's frame. Frame Number at 0 would make Bullet Count's frame be frame 0, which is nonexistent.

And with the explosion I was just putting the action in the wrong area. :roll:
B
2
G
3
Posts: 12
Reputation: 874

Post » Tue Jun 23, 2009 7:28 pm

[quote="Mr. Bucket":v9j7we1m]Frame Number can never reach zero! Because to Fire (and therefore reduce Frame Number by 1), Frame Number must be greater than 1.[/quote:v9j7we1m]
Then allow firing when greater or equal to 1.

[quote:v9j7we1m]Frame Number at 0 would make Bullet Count's frame be frame 0, which is nonexistent.[/quote:v9j7we1m]
Then if the frame number variable is 0, then set it to a different animation frame or animation.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Tue Jun 23, 2009 7:39 pm

Whenever you get the time could you send me a fixed .cap? I swear, I just can't get it right. :(
B
2
G
3
Posts: 12
Reputation: 874

Post » Wed Jun 24, 2009 1:20 am

On second thought, you can forget about it. I figured it out! Funny how you can take a long break when you're having a problem and fix it in about a minute when you come back.

B
2
G
3
Posts: 12
Reputation: 874

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests