Alternative to sleep?
Moderators: Moderators, Documentation Writers
Alternative to sleep?
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.
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.
Re: Alternative to sleep?
I appreciate it, but its rather like spawing a new process with delay rather than using it as a pause,Spherical wrote:http://forums.openkore.com/viewtopic.php?f=36&t=18947
what if i hooked it to ai_pre? how can i control the timeouts of triggers
ex:
Code: Select all
sub ai_pre {
Commands::run("c Test");
}
I need some delay, or timeout if you will.Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test
Foo: Test
but thanks to your code about Timeout hook, I used it on something but not on this,
I saw someone using
but I can't get it, I can't find the "timeOut" hook.if (timeOut(time, 2))
Just like old times.
Re: Alternative to sleep?
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.
Re: Alternative to sleep?
nonetheless it's still not working on a sub hooked in ai_pre, it still spams.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.
Code: Select all
sub act {
message ("try");
}
sub main {
$taskManager->add(Task::Timeout->new(
function => sub{act},
seconds => 5,
));
}
try
try
try
try
try
Just like old times.
Re: Alternative to sleep?
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:
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.
Code: Select all
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");
}
Re: Alternative to sleep?
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.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.
Just like old times.
Re: Alternative to sleep?
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.gamenikko wrote: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.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.
by the way packet_privMsg has the following variables:
Plugins::callHook('packet_privMsg', {
privMsgUser => $privMsgUser,
privMsg => $privMsg,
MsgUser => $privMsgUser,
Msg => $privMsg
});
Re: Alternative to sleep?
Well thanksSpherical wrote: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.gamenikko wrote: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.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.
by the way packet_privMsg has the following variables:
Plugins::callHook('packet_privMsg', {
privMsgUser => $privMsgUser,
privMsg => $privMsg,
MsgUser => $privMsgUser,
Msg => $privMsg
});
Problem solved now,
Just like old times.