How do I prevent players from spamming the same event?

0 favourites
  • 3 posts
  • Im creating very basic game. My problem is that if I press F many times it overlaps everytime how can i do somekind of wait command for an event.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The question is too vague. You need to add a condition to "On key pressed" event, to check if the previous action has finished.

    .

    Here is a simple way to restrict pressing a key only once a second:

    Global Variable timer
    
    On "F" key pressed
    Compare variable timer<(time-1)
    ..... Set timer to time
    ..... (do the other stuff)
    
  • like dop2000 said you have to check if previous action completed, the more complicated yet perfect way of doing it is by using functions, not sure if this is still a thing in C3 or it got replaced by the javascript...

    but the idea is if function plugin is still a thing you can do something like bellow pseudo-code

    Solution 1:

    1. on F pressed, 
     1.1 Sub event if function "spawn action F completed" > action call function "spawn action F"
    
    2. On function "spawn action F" > do this actions 0-n++
    

    having a timer from my experience, it delays things and then glitches happen, with a delay... but it depends on how you implement it, the solution 3 shouldn't create any delayed glitches.

    Solution 2:

    have 1 boolean or global variable that u turn on and off while actions happen, and you have something like bellow:

    Global Variable "checkF" = 0;
    
    1. On "F" Key pressed 
     1.1 if checkF = 0 > action > set CheckF = 1
    	 do something
    			 do something
    			 set checkF = 0
    
    

    this will not let you tap super fast and overlap things but will create like a 0.1-0.2 delay in your spawning action when you press "F" it will still overlap but not as fast.

    Solution 3:

    The timer

    Global Variable "timer" = 0;
    
    
    1. everytick (or if timer) > 0 >subtract from timer 1 (this happens everytick or dt, so is closed as being miliseconds and not seconds, to increase delay either increase 2.1 set timer to 1000 or set the value of subtraction to 0.2 or 0.1)
    
    2. On "F" pressed 
     2.1 if timer =< 0 - action
    		 action 
    		 action 
    		 set timer to 100 (in miliseconds if you subtract 1 everytick like we do above)
    
    3. if timer < 0 - set timer to 0 [this is fail safe so the timer never goes under 0]
    
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)