Openkore.com

OpenKore Forums
It is currently 17 Oct 2019, 06:45

All times are UTC - 5 hours [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Alternative to sleep?
PostPosted: 11 Jan 2013, 10:42 
Offline
The Way Of Human
The Way Of Human
User avatar

Joined: 16 Aug 2009, 03:47
Posts: 192
Location: Gonryun
sleep pauses everything including the console,
I couldnt find what kore uses to act as a delay.
or something like and event loop to act as a pause, simillar to what macro plugin uses.

_________________
Just like old times.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 11 Jan 2013, 13:14 
Offline
Human
Human

Joined: 03 Jan 2013, 00:05
Posts: 29
viewtopic.php?f=36&t=18947


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 11 Jan 2013, 14:07 
Offline
The Way Of Human
The Way Of Human
User avatar

Joined: 16 Aug 2009, 03:47
Posts: 192
Location: Gonryun
Spherical wrote:
http://forums.openkore.com/viewtopic.php?f=36&t=18947


I appreciate it, but its rather like spawing a new process with delay rather than using it as a pause,
what if i hooked it to ai_pre? how can i control the timeouts of triggers

ex:

Code:
sub ai_pre {
Commands::run("c Test");
}


result:
Quote:
Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test


I need some delay, or timeout if you will. :D
but thanks to your code about Timeout hook, I used it on something but not on this,
I saw someone using

Quote:
if (timeOut(time, 2))


but I can't get it, I can't find the "timeOut" hook.

_________________
Just like old times.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 11 Jan 2013, 15:30 
Offline
Human
Human

Joined: 03 Jan 2013, 00:05
Posts: 29
Timeout isnt a hook, I think it's either in utils or tasks, but im not sure. The method in that thread I linked is much better and you should use it, trust me.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 11 Jan 2013, 15:44 
Offline
The Way Of Human
The Way Of Human
User avatar

Joined: 16 Aug 2009, 03:47
Posts: 192
Location: Gonryun
Spherical wrote:
Timeout isnt a hook, I think it's either in utils or tasks, but im not sure. The method in that thread I linked is much better and you should use it, trust me.


nonetheless it's still not working on a sub hooked in ai_pre, it still spams.

Code:
sub act {

   message ("try");
   
}

sub main {
   $taskManager->add(Task::Timeout->new(
               function => sub{act},
               seconds => 5,
               ));
}


result:
Quote:
try
try
try
try
try

_________________
Just like old times.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 12 Jan 2013, 00:12 
Offline
Human
Human

Joined: 03 Jan 2013, 00:05
Posts: 29
I don't understand what you're asking for then. No matter what you call in a loop it's going to be called very rapidly you could do something like the following:
Code:
my $control;

//add hook for ai_pre or some other way to get an initial call of the function.

sub AIPre {
   if ( !$control ) {
      &sayHi;
      control = 1;
   }
}

sub sayHi {
   $taskManager->add(Task::Timeout->new(
      object => undef,
      function => \&callSayHi,
      seconds => 1,
      inGame => 1,
      weak => 1
   ));
   Commands::run("c Test");
}


However, you would never want to pause one of the main loops (it would cause some major issues such as lack of responsiveness etc. So "pausing" isn't really an option.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 12 Jan 2013, 00:34 
Offline
The Way Of Human
The Way Of Human
User avatar

Joined: 16 Aug 2009, 03:47
Posts: 192
Location: Gonryun
Quote:
However, you would never want to pause one of the main loops (it would cause some major issues such as lack of responsiveness etc. So "pausing" isn't really an option.


Yeah I mean I need and event_loop that could be easily used, by the way what I'm trying to do is to add some delay so the bot won't respond to PM's to quickly, kinda words per minute thing.

_________________
Just like old times.


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 12 Jan 2013, 09:23 
Offline
Human
Human

Joined: 03 Jan 2013, 00:05
Posts: 29
gamenikko wrote:
Quote:
However, you would never want to pause one of the main loops (it would cause some major issues such as lack of responsiveness etc. So "pausing" isn't really an option.


Yeah I mean I need and event_loop that could be easily used, by the way what I'm trying to do is to add some delay so the bot won't respond to PM's to quickly, kinda words per minute thing.

Then you need to be hooking packet_privMsg, don't do anything with the loops. When packet_privMsg is called create a timer with a random delay and have that call your respond function.

by the way packet_privMsg has the following variables:
Plugins::callHook('packet_privMsg', {
privMsgUser => $privMsgUser,
privMsg => $privMsg,
MsgUser => $privMsgUser,
Msg => $privMsg
});


Top
 Profile  
 
 Post subject: Re: Alternative to sleep?
PostPosted: 12 Jan 2013, 10:56 
Offline
The Way Of Human
The Way Of Human
User avatar

Joined: 16 Aug 2009, 03:47
Posts: 192
Location: Gonryun
Spherical wrote:
gamenikko wrote:
Quote:
However, you would never want to pause one of the main loops (it would cause some major issues such as lack of responsiveness etc. So "pausing" isn't really an option.


Yeah I mean I need and event_loop that could be easily used, by the way what I'm trying to do is to add some delay so the bot won't respond to PM's to quickly, kinda words per minute thing.

Then you need to be hooking packet_privMsg, don't do anything with the loops. When packet_privMsg is called create a timer with a random delay and have that call your respond function.

by the way packet_privMsg has the following variables:
Plugins::callHook('packet_privMsg', {
privMsgUser => $privMsgUser,
privMsg => $privMsg,
MsgUser => $privMsgUser,
Msg => $privMsg
});


Well thanks :D
Problem solved now,

_________________
Just like old times.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group