One object creation at a time? Single bullet at a time?

This forum is currently in read-only mode.
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • I'm trying to do something where you can only create one object at a time. In this case, shooting a single bullet at a time. I'd tried doing something like...

    Hand: Is on-screen

    MouseKeyboard: On key C pressed

    System: Is global variable 'Character' Equal to 2

    SystemCreate object Hand 0 on layer "Playing Field" at (0, 0) from Player 1 's pivot point

    That first event, I tried inverting, so as to tell the event, "If this object is NOT on-screen, and if THIS key is pushed while THIS character is being used, THEN go ahead and spawn/create the object." but for some reason, somehow, I cannot get a one-object limit on this no matter what I do. I don't wanna do a global object just for this either, but does anyone have any ideas on how I can do this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Trigger Once is your friend. When you press a button, it actually stays pressed for several ticks before it is released, no matter how lightly you tap it. In that case you want to add Trigger Once after the MouseKeyboard: On key C pressed.

    Trigger Once basically executed the event once only, then blocks it until condition returns false, then it is reset and waits for next true from the condition. You can find it in System Object.

  • Have something spawn the object at the position you want, using the method you want, then destroy itself (use an invisible sprite somewhere), then if for example you want to be able to spawn another bullet once the first one is eventually destroyed, just have the invisible spawn sprite respawned on the bullets death. That should work?

  • I already tried doing some "Trigger Once" stuff before you said that and it didn't work. Even when I tried using it specifically the way you described, it still didn't work. It wouldn't spawn the object at all. Is it a bug with Construct? o_O

    Oh. You think I mean a rapid-fire thing. No, I mean just a single bullet at a time. Until the object's gone, another cannot be created. That's what I meant.

  • Oh. Sorry, slight misunderstanding! Well, in that case Lost's method should work - or you can use a variable which stores the number of bullets (Object.Count) - only fire if it is less than one. If you expect to use more bullets, you'll have to distinguish that one somehow (by a variable, for example).

  • Example

    There you go, from what I can tell it does what you're wanting to do.

  • [quote:3t9os9zo]Oh. Sorry, slight misunderstanding! Well, in that case Lost's method should work - or you can use a variable which stores the number of bullets (Object.Count) - only fire if it is less than one. If you expect to use more bullets, you'll have to distinguish that one somehow (by a variable, for example).

    Funny you say that JUST after figuring out a work-around using a private variable as a switch. The event only works if the private variable is 0. Pressing the fire button sets the private variable to 1, preventing any further firing. In the same event that destroys the bullet, the private variable is set to 0.

    I was using this as a "boomerang"-type effect for a grappling hook thing, hence the "Hand" object. The character reaches out to grab a grapple point, but after a certain amount of distance, the hand retracts back to the character, and of course, we can't have more than one created at a time.

  • Example

    There you go, from what I can tell it does what you're wanting to do.

    Oohh, it DOES. NOW I know what you mean with that "spawner" stuff. Do, either with a dummy variable, or dummy sprite, I gotta use some cumbersome way as a work-around, sadly. Thanks. ^_^

  • Well if you use the dummy sprite, you could have it appear as something, maybe a puff of smoke or crackle of electricity etc. at the end where the grapple pops out. That way the sprite has more than one use to it.

    For cleanliness sake though, I'd probably go with the variable suggestion of Mipey's, unless using the sprite method offers something extra for what you have in mind.

  • When you press a button, it actually stays pressed for several ticks before it is released, no matter how lightly you tap it. In that case you want to add Trigger Once after the MouseKeyboard: On key C pressed.

    Not quite. On Key Pressed already only triggers once. I think you're thinking of Key Down.

  • You don't even need any variables. Just add a 'Compare values' system condition to the event that fires a bullet: Bullet.Count = 0. Then you can only shoot when there are no bullets. Simple!

  • Ah! Damnit Ashley, again! @ How is it you ALWAYS have so much more knowledge than everyone else? Even in a thread of like, 3 or 4 people discussing my little problem, NO ONE mentioned that! That's awesome. ^_^ Thanks.

  • I did, like, write the runtime

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