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,338
    Thanks given
    158
    Thanks received
    1,724
    Discord
    View profile
    Rep Power
    5000
    You need to create a new delayed task/event for this.
    Thanks, Kevin.
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    nice


    Join Date
    Jul 2014
    Posts
    665
    Thanks given
    288
    Thanks received
    341
    Discord
    View profile
    Rep Power
    2952
    yes the whole server stops because ur stopping the main thread
    Reply With Quote  
     

  5. Thankful user:


  6. #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  
     

  7. #5  
    Banned

    Join Date
    Jun 2010
    Age
    23
    Posts
    4,836
    Thanks given
    1,676
    Thanks received
    1,563
    Discord
    View profile
    Rep Power
    0
    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. ]
    Reply With Quote  
     

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

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    21
    Posts
    1,535
    Thanks given
    668
    Thanks received
    402
    Rep Power
    971
    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. ]


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

  9. #7  
    Extreme Donator

    Patrity's Avatar
    Join Date
    Jul 2008
    Age
    28
    Posts
    937
    Thanks given
    173
    Thanks received
    306
    Discord
    View profile
    Rep Power
    882
    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 Application Development
    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
  •