Help doing something else if conditions aren't met?

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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?

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

    <img src="http://img268.imageshack.us/img268/8359/aaaaaaaaayja.jpg">

    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.

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

    This doesn't work:

    <img src="http://img269.imageshack.us/img269/1452/figure1.gif">

    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:

    <img src="http://img8.imageshack.us/img8/999/figure2.gif">

    <img src="http://img170.imageshack.us/img170/7993/figure3.gif">

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This doesn't work:

    <img src="http://img269.imageshack.us/img269/1452/figure1.gif">

    '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.

    <img src="http://img8.imageshack.us/img8/999/figure2.gif">

    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.

    <img src="http://img170.imageshack.us/img170/7993/figure3.gif">

    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

  • 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.

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

    http://www.quickfilepost.com/download.do?get=90e1f000de76dc95b9600e75baa46596

    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.)

  • 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.

    Then compare it to 0, not 1

    [quote:2l62emm6]how can I make an object do something when an instance of it is created?

    Follow it by an action. Eg.:

    -> Create object 'Explosion'

    -> Set 'Explosion' angle to random(360)

  • 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.

  • Frame Number can never reach zero! Because to Fire (and therefore reduce Frame Number by 1), Frame Number must be greater than 1.

    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.

    Then if the frame number variable is 0, then set it to a different animation frame or animation.

  • Whenever you get the time could you send me a fixed .cap? I swear, I just can't get it right.

  • 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.

    <img src="http://img37.imageshack.us/img37/9161/fixed.gif">

  • Did this a while ago, works fine. Might not be the best way to do it, somebody feel free to prove me wrong.

    Shoot - Space

    Left and Right Arrow Keys to move

    Jump - Up arrow

    Reload - R

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)