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

For questions about using Classic.

Post » Wed Dec 16, 2009 6:45 am

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?
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 6:49 am

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.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 16, 2009 6:51 am

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?
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 6:55 am

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.
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 7:06 am

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).
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Dec 16, 2009 7:11 am

Example

There you go, from what I can tell it does what you're wanting to do.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 7:12 am

[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).[/quote:3t9os9zo]

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.
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 7:17 am

[quote="Lost my Keys":2kx7ahfl]Example

There you go, from what I can tell it does what you're wanting to do.[/quote:2kx7ahfl]

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. ^_^
B
4
S
2
G
4
Posts: 164
Reputation: 1,878

Post » Wed Dec 16, 2009 7:21 am

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.
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Wed Dec 16, 2009 10:22 am

[quote="Mipey":2m39b117]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.[/quote:2m39b117]

Not quite. On Key Pressed already only triggers once. I think you're thinking of Key Down.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests