www.webdeveloper.com
Results 1 to 7 of 7

Thread: Need help with sleep

  1. #1
    Join Date
    Sep 2011
    Posts
    1

    Need help with sleep

    Hello, i got this javascript :

    Code:
    $(document).keyup(function(e){
      if(e.which==69){
    	for(var i in g.npc){
    	  if ((Math.abs(hero.rx - g.npc[i].x) <= 1 && Math.abs(hero.ry - g.npc[i].y) <= 1) && (g.npc[i].type == 2 || g.npc[i].type == 3)){
    		message('id: "'+g.npc[i].nick+'"');
    		_g("reg&a=name&auto=1&id=-"+i);
    		break;
    	  }
    	}
      }
    });
    This javascript is used when key "E" pressed, i need add 5000 milisecound sleep to that function ( even if I press the E key a few times in a row, the function will be executed only once in 5000 milliseconds).

    I tried do that with setTimeout, but can't

    Can someone help me?

    Thanks

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by creif View Post
    Hello, i got this javascript :
    You got that... JQuery? Prototype? MooTools? Scriptaculous? Google API? yahoo API? Other JavaScript library? Which one?

    Please, when you write a code which is a custom part of a JavaScript library, specify which library you have used.

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    function me(e){
      if(e.which==69  && (!me.last || (+new Date - me.last) >5000)){
       me.last=+new Date
     ...
    changes in red

  4. #4
    Join Date
    Sep 2011
    Posts
    7
    yeah what is the library that was used?

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by marketingboss View Post
    yeah what is the library that was used?
    what do you mean?
    isn't it obvious that it's jQuery?

    jQuery is used on MOST big sites, learn it or perish.

    and, just to be clear, the question had nothing to do with any library, it's a js question that had a js answer...

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by rnd me View Post
    what do you mean?
    isn't it obvious that it's jQuery?
    No, it is not obvious. The presumption that all the coders in this world know perfectly the JQuery syntax (to be able to recognize it even within 3 lines of code) is wrong.

    In fact, isn't obvious that, if you have a JQuery problem, you should start by telling everybody from the beginning: "Hey, I have a JQuery problem!"? That should filter better your needs, so that only those who know JQuery will open, read the thread and give a solution.

    Now, only this is really obvious!

  7. #7
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by Kor View Post
    In fact, isn't obvious that, if you have a JQuery problem, you should start by telling everybody from the beginning: "Hey, I have a JQuery problem!"? That should filter better your needs, so that only those who know JQuery will open, read the thread and give a solution.
    ok, but it wasn't a jQuery problem. i don't think that using the lib should prevent good coders like kor from helping. I've been anti-jQuery since the beginning but it behooves me to hold at least a basic familiarity with its most-used features.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles