The Daily Click ::. Forums ::. Klik Coding Help ::. How do you make a weapon fire when you press a button, but not too fast?
 

Post Reply  Post Oekaki 
 

Posted By Message

siven

I EAT ROCKS

Registered
  03/11/2008
Points
  604

Wii OwnerVIP Member
26th January, 2011 at 10:32:25 -

so id like to make it so my pistols are shot when you press the button, not a press and hold kinda deal, but i did what seemed logical and it didnt work.
heres what the code looks like...
Object(Guninhand) Is faceing ->
Limit Condition for 0.30secs
+Upon Pressing D key
= Fire bullet

logically that would mean you can only shoot every 0.30 seconds, but what happens is you shoot once, and than it wont let you shoot in that direction again. also, there are each of those events for the other directions as well. the only reason i dont have hte bullet fireing in the direction the guninhand is pointing is because in order to have an arm pointed upward on the left side and on the right side, i had to use the 2 spots on the animation thing to the left and right of the UP slot, if that makes any sense. anyone know what i did incorrectly?

 
[Game design makes my brain feel like its gonna explode.]

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
26th January, 2011 at 13:10:09 -

Repeat while is pressed "Space"
+ Active.AltA = 0
Then
> Active.AltA = 10
> Fire Bullet

If Active.AltA > 0
Then
> Active.AltA = Active.AltA - 1



Where 10 is the cooldown time.

Edited by an Administrator

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th January, 2011 at 13:10:34 -

I'd use a flag or alterable value, depending on how long you want the pause to be.

Object is facing ->
+ Object flag 0 is off
+ Upon Pressing D key
= Fire bullet
+ Set Object flag 0 on

Every 0.30 seconds (Or always, or whatever)
= Set object flag 0 off

Edit: Bah! Too slow. Use AssaultAndy's method. It will work independent of the timer.

Edited by OMC

 

  		
  		

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
26th January, 2011 at 14:53:44 -

Eww thats not typical of you to recommend that sort of method, OMC.

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th January, 2011 at 19:10:36 -

Well, I was going to use an alterable value method, but I changed my mind for some reason.

Must not have been thinking straight this morning!

 

  		
  		

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
26th January, 2011 at 19:39:06 -

Then you would die if you saw my code Gamester...especially the code in OMC's game that I helped work on.

 
n/a

s-m-r

Slow-Motion Riot

Registered
  04/06/2006
Points
  1078

Candle
26th January, 2011 at 20:51:49 -

(for all the noobs and fellow novices out there)

I remember reading somewhere that using the Timer to have a set time for events isn't as effective as using an alterable value, as one machine may be able to keep up with the timer, but others might not. As I am not the best at coding, I tend to stick with using Alterable Values in all cases where a timer might do, simply because if there's a sequence of events based upon timers and/or regular intervals, they'll always keep pace with the way the rest of the game is running.

But most of y'all know this already. My point is that I just shy away from using the Timer object unless there are very, very few Active Objects and/or functions/events.

 
n/a

JetpackLover



Registered
  01/03/2007
Points
  212
26th January, 2011 at 23:38:39 -

Why not use TimeX and use the nloop function?

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
26th January, 2011 at 23:57:39 -


Originally Posted by s-m-r
(for all the noobs and fellow novices out there)

I remember reading somewhere that using the Timer to have a set time for events isn't as effective as using an alterable value, as one machine may be able to keep up with the timer, but others might not. As I am not the best at coding, I tend to stick with using Alterable Values in all cases where a timer might do, simply because if there's a sequence of events based upon timers and/or regular intervals, they'll always keep pace with the way the rest of the game is running.

But most of y'all know this already. My point is that I just shy away from using the Timer object unless there are very, very few Active Objects and/or functions/events.



For the perfectionist its also less accurate as you cannot reset the timer.

If you have an event that says

Z is pressed
+ Every 00.05
- Shoot

and you start pressing Z at 0.02 then the object shoots 00.02 seconds earlier

if that makes sense.

Negligible? Probably, but it bothers me. You can reset the alterable value if the player lets go of shoot.

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
27th January, 2011 at 01:11:56 -

I use no timer events at all. But...



If you have an event that says

Z is pressed
+ Every 00.05
- Shoot

and you start pressing Z at 0.02 then the object shoots 00.02 seconds earlier



It still makes me cringe because I know this has always been how it works, but I noticed in TGF2NE (only MMF2 product I've used) it's been "fixed".

Every 00.05 + While Z is pressed uses the frame timer,
While Z is pressed + Every 00.05 starts a unique count

So OMC's version should work as Object Flag 0 on + Every 00.30

It still sux because it uses the timer!

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
27th January, 2011 at 01:59:31 -

Wow seriously?

Thanks o_o.

but yeah timer = bleh

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
27th January, 2011 at 06:15:36 -

I still have a nasty habit of using timer events. I also have a nasty habit of stopping at a McDonalds and suddenly getting hungry. I know it's horrible for me, and when I think about it long enough, I go for the much better alternative. I think this is a pretty good analogy.

 
http://www.facebook.com/truediamondgame

siven

I EAT ROCKS

Registered
  03/11/2008
Points
  604

Wii OwnerVIP Member
27th January, 2011 at 08:54:44 -

thanks everyone! i think i gathered what info that i need to finish this little deal up. also, ive learned... Timer = evil.

 
[Game design makes my brain feel like its gonna explode.]

JetpackLover



Registered
  01/03/2007
Points
  212
27th January, 2011 at 09:21:06 -

TimeX is pretty gooooood.

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
27th January, 2011 at 10:59:37 -


Originally Posted by DudeHuge
TimeX is pretty gooooood.



Yeah it can be nice, as long as you manage to start the "nloop count" from when you want to, i.e the same difficulty as resetting the timer.

Alterable values are the best for most situations, and since MMF2 has a shitload of em in every object you can afford to use them.

He, that was always a blast in MMF1.2, trying to make A.I with three alterable values and the flags.

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
27th January, 2011 at 14:30:13 -

Ah, the days of using the timer in jump events. Uncontrollable variable jumping lol.

 
.

siven

I EAT ROCKS

Registered
  03/11/2008
Points
  604

Wii OwnerVIP Member
27th January, 2011 at 18:30:06 -

Well, just so you guys can see, this is what i did.

+Object(Guninhand) Is faceing ->
+Alterable value A of Guninhand is lower or = to 0
+Upon Pressing D key
= Fire bullet
= add 20 to alterable value A of guninhand

and then...

+Every 0.1 seconds
+alterable value a of guninhand greater than 0
=subtract 0.1 from alterable value A

it works just fine too.

 
[Game design makes my brain feel like its gonna explode.]

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
27th January, 2011 at 18:31:42 -

You should switch the every 0.1 seconds out for an always.

 

  		
  		

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
28th January, 2011 at 02:49:54 -


Originally Posted by OldManClayton
You should switch the every 0.1 seconds out for an always.


Always is faster then every 0.1 seconds.

 
http://www.facebook.com/truediamondgame

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
28th January, 2011 at 03:00:30 -

Which would be easily fixed by adding a higher number to the alterable value.

 

  		
  		

siven

I EAT ROCKS

Registered
  03/11/2008
Points
  604

Wii OwnerVIP Member
29th January, 2011 at 02:21:26 -

what would be the point in making it an always event? using the 0.1 secs makes it easier to moderate the amount of time between shots fired.
and i read something somewhere that said the fastest mmf2 can process events is 0.2 secs, is that true?

 
[Game design makes my brain feel like its gonna explode.]

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
29th January, 2011 at 05:25:59 -

No, MMF will process as fast as your computer can handle and within the frame rate limit.

OMC is right, the timer event may work fine on your computer, heck it may even run fine on every computer, but it's a bad habit to get into because once you start using larger amounts of time you'll start to have inconsistencies if the game runs at an inconsistent frame rate.

The Timer is based on real time, and not in-game time. That's the only real problem.

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
29th January, 2011 at 13:23:45 -

Siven, once we've learned that the timer is evil, we use no timer at all!


and i read something somewhere that said the fastest mmf2 can process events is 0.2 secs, is that true?



Before MMF2 introduced framerate settings, all klik games ran at 50FPS. I.e., if the game was running at maximum speed (which it rarely would be), the events would run and the screen would be redrawn every 0.02 seconds (protip: this is completely different from every 0.2 seconds). The 'Always' event means 'every frame'.

Unless you use 'machine-independent speed', which I remember typically being gamebreaking, the game speed is going to fluctuate with framerate. The timer isn't, so it's a one-way ticket to inconsistency land.

 
n/a

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
30th January, 2011 at 11:27:20 -

So all in all.

This is is how your conditions and events should go:

+ Upon pressing "Fire button"
+ If guninhand is faceing direction 0
+ Active.altval = 0
- Fire bullet
- Set Active.altval to (time before you can shoot again, maybe 10)

+ While Active.altval > 0
- Active.altval = -1

 
dont make me divide by zero...

the Pilgrim



Registered
  31/05/2004
Points
  56
16th April, 2011 at 16:07:15 -


Originally Posted by Assault Andy
Repeat while is pressed "Space"
+ Active.AltA = 0
Then
> Active.AltA = 10
> Fire Bullet

If Active.AltA > 0
Then
> Active.AltA = Active.AltA - 1



Where 10 is the cooldown time.



Why haven't I figured this one out? This was just the one I needed for my comming new project! Thanks!

 
"I am always on the move, becuase I am a pilgrim in this world."

The Chris Street

Administrator
Unspeakably Lazy Admin

Registered
  14/05/2002
Points
  48488

Game of the Week WinnerClickzine StaffAcoders MemberKlikCast StarVIP MemberPicture Me This Round 35 Winner!Second GOTW AwardYou've Been Circy'd!Picture Me This Round 38 Winner!GOTM December Third Place!!
I am an April FoolKliktober Special Award Tag
16th April, 2011 at 16:16:19 -

I thought "Always" equated to "0.02" seconds.

 
n/a

Liquixcat

Administrator
Lazy Coder

Registered
  08/12/2002
Points
  201

VIP MemberLikes TDCKitty
19th April, 2011 at 12:29:30 -

I read an article that basically said 0.02 timer is equal to Always. Even if that's true it's just better habit to use always.

PS. How i'd do it.

code-------
+always
subtract from value 1

+Space key down
+value<=0
-Fire bullet
-set value=10
end code-------



 
thinking is like pong, it's easy, but you miss sometimes.

Jon Lambert

Administrator
Vaporware Master

Registered
  19/12/2004
Points
  8235

VIP MemberWii OwnerTDC Chat Super UserI am an April FoolSSBB 3265-4741-0937ACCF 3051-1173-8012360 Owner
19th April, 2011 at 20:51:32 -


Originally Posted by The Chris Street
I thought "Always" equated to "0.02" seconds.

That's only when the framerate is 50. "Always" equates to FrameRate/100.0. The default framerate is 50, so by default, "Always" is "Every 0.02 seconds".

 
Sandwich Time!Whoo!

JoyCheck & KeyCheck Widgets
For easy implementation of customizable joystick and keyboard controls.
http://www.create-games.com/download.asp?id=8364

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
19th April, 2011 at 23:12:55 -

Yeah, I was gonna say. In-game loops are completely independent of time. This is precisely why timer events are a bad idea to use, because when the game slows down, timer events still fire on time. "Always" is based on in-game loops, so if you increased the framerate, naturally "always" would be a faster than 0.02 seconds. Likewise, if you slowed the framerate down, "always" would be slower than 0.02 seconds. Slow it down to 30fps and Always will literally fire 30x a second.

 
http://www.facebook.com/truediamondgame

Jacob!



Registered
  17/06/2011
Points
  153
24th April, 2011 at 06:01:16 -

No, you're all doing it wrong. The original poster had it almost right.

Repeat While "Fire" is pressed
Restrict Actions for 0.10 seconds
-Shoot Object

 
Have you even been far as decided to use even go want to do look more like?

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
24th April, 2011 at 12:54:23 -

Personally, I think you should do what you can to make sure the game will run at full speed on as low a spec computer as possible (include options to disable special effects, etc if need be) - and then if the player's computer isn't fast enough, that's their problem.
There's no point trying to make a game run normally but at slow speed.

 
n/a

Duncan

Thelonious Dunc

Registered
  18/05/2002
Points
  552

VIP Member
24th April, 2011 at 13:29:59 -


There's no point trying to make a game run normally but at slow speed.



But that's what MMF does for everything else by default. Can you really account for everything that might trigger the tinest dip in performance? The inconsistency is just going to lurk in the shadows until it gets an opportunity to break the game.

If a game's perfectly playable with those special effects enabled, but for some reason I can't make a particular jump while something's exploding (edit: or because the midi file playing changes or whatever), I'm going to be inclined to think it's the developer's fault.





Edited by Duncan

 
n/a

nim



Registered
  17/05/2002
Points
  7234
24th April, 2011 at 14:23:16 -

This is an awful lot of talk for such a simple problem. Personally I'd use the method suggested by Assault Andy in the first reply.

 
//

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
24th April, 2011 at 14:39:25 -

So would I

Never use timers.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
24th April, 2011 at 14:42:18 -

'Cept for when you need to access real time.

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
24th April, 2011 at 15:04:21 -

I still wouldn't use timers, since they don't let you access real time anyway (see rest of thread). I'm pretty sure TimeX can get time independent of framerate.

Edited by an Administrator

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
24th April, 2011 at 19:07:20 -

This is how I do it.

http://www.whenthereisnoroominhellthedeadwalktheearth.com/MMF/firingspeedtutorial.mfa

Image

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
25th April, 2011 at 03:12:17 -

Chris - that looks good but remove the "Every 00-01"" from everywhere. Your code will run exactly the same, except it will be consistent on slow machines

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
25th April, 2011 at 06:06:09 -

How slow of a machine are we talking?

I've run games I've made on so many pieces of shit and they still run the same.

But yeah I need to get in that habit of using always instead. Thanks! happy easter

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
25th April, 2011 at 15:12:25 -

Anything that runs below the target FPS will run differently. It's not likely that someone is using a computer that slow, but it's not just that. If you freeze the app (such as with grabbing the title bar - I think), or your computer happens to lag for a second (due to some other process), it will run differently if you use timers. If you use counters/MMF framerate instead then it will run the same on all machines, albeit slower. In your code, there's no point in having the Every 00-01 in there.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2723
25th April, 2011 at 15:35:14 -

I just really like timed events like: every 02'13, they just add some unpredictable behaviour in your game.

But I recommend Andy's method too.

 
Image jenswa.neocities.org

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
25th April, 2011 at 15:49:09 -


Originally Posted by Jenswa
I just really like timed events like: every 02'13, they just add some unpredictable behaviour in your game.

But I recommend Andy's method too.




It's even more unpredictable with a Counter=Random(3276*Random(23)!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image
   

Post Reply



 



Advertisement

Worth A Click