Thread: Execute code after x amount of time. HELP!

Results 1 to 7 of 7
  1. #1 Execute code after x amount of time. HELP! 
    Registered Member
    Join Date
    Apr 2014
    Posts
    20
    Thanks given
    0
    Thanks received
    7
    Rep Power
    11
    Hello, I'm using PI source and right now I have this code:

    if (itemId == 1779 && objectId == 7849) {

    try
    {
    Thread.currentThread().sleep(2000);
    }
    catch(InterruptedException ex)
    {
    Thread.currentThread().interrupt();
    }
    c.sendMessage("test");
    }

    I want it to do this "c.sendMessage("test");" after 2 seconds, only problem with my code is that the whole server stops for 2 seconds, I just want the code to be delayed by 2 seconds.
    Reply With Quote  
     

  2. #2  
    Administrator

    Kevy's Avatar
    Join Date
    Jul 2006
    Posts
    1,156
    Thanks given
    84
    Thanks received
    1,580
    Discord
    Kevy#1197
    Rep Power
    4713
    You need to create a new delayed task/event for this.
    Thanks, Kevin.
    Reply With Quote  
     


  3. #3  
    ya


    Join Date
    Jul 2014
    Posts
    555
    Thanks given
    175
    Thanks received
    184
    Discord
    Suic#0543
    Rep Power
    1387
    yes the whole server stops because ur stopping the main thread
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Registered Member
    Join Date
    Apr 2014
    Posts
    20
    Thanks given
    0
    Thanks received
    7
    Rep Power
    11
    Quote Originally Posted by Kevy View Post
    You need to create a new delayed task/event for this.
    Can you tell me more, I've tried this also

    if (System.currentTimeMillis() - c.ft > 5000) {
    c.ft = System.currentTimeMillis();

    c.sendMessage("");
    }

    }else{
    c.sendMessage("test");
    }

    That didnt work as planned either.
    Reply With Quote  
     

  6. #5  
    Super Donator

    Tyluur's Avatar
    Join Date
    Jun 2010
    Posts
    4,051
    Thanks given
    1,369
    Thanks received
    1,289
    Rep Power
    718
    Quote Originally Posted by bajskorv View Post
    Can you tell me more, I've tried this also

    if (System.currentTimeMillis() - c.ft > 5000) {
    c.ft = System.currentTimeMillis();

    c.sendMessage("");
    }

    }else{
    c.sendMessage("test");
    }

    That didnt work as planned either.
    i recommend you read this thread line by line [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]

    Quote Originally Posted by Velocity View Post
    i'd love to get called in the middle of the night just to hear an indian voice whisper "the nulls are back friend, how i fix"
    Quote Originally Posted by Savions View Post
    ive seen eastern europe prostitutes with a brighter future than this project
    Reply With Quote  
     

  7. #6  
    Wut can u say when theres nothin to tell

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    20
    Posts
    1,527
    Thanks given
    640
    Thanks received
    384
    Rep Power
    946
    Quote Originally Posted by Tyluur View Post
    i recommend you read this thread line by line [Only registered and activated users can see links. ]
    i would recommend first learning the basics of the language




    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #7  
    Extreme Donator

    Patrity's Avatar
    Join Date
    Jul 2008
    Age
    27
    Posts
    800
    Thanks given
    66
    Thanks received
    151
    Discord
    Patrity#0001
    Rep Power
    292
    There's a ton of ways to do this.
    Sometimes you need to expand your google searches. Remember that Java is Java, and googling "RSPS..anything" will not get you anywhere.

    [Only registered and activated users can see links. ]
    Free map releases: [Only registered and activated users can see links. ]


    [Only registered and activated users can see links. ]
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Replies: 0
    Last Post: 08-15-2016, 10:55 PM
  2. Replies: 2
    Last Post: 06-30-2013, 01:20 AM
  3. Execute code after X amount of time?
    By Tigra in forum Help
    Replies: 13
    Last Post: 12-27-2012, 10:50 PM
  4. Replies: 0
    Last Post: 09-14-2009, 01:09 AM
  5. Replies: 47
    Last Post: 05-01-2008, 02:25 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •