I'm writing a plugin. I need it to wait 60 seconds after running a command and run it again... and again...
I tried to use "sleep 60;", but that pauses the entire program, and it stop sending the sync packets, so the openkore disconects. How could i get the same behavior? It would be nice to stop only the plugin.
Also, i need this function to be running always, or at least from 60 to 60 seconds. I'm using the "mainLoop_post" hook, but probably isnt the best option. I would like to get some advices.
Perl Help
Moderator: Moderators
-
- Plain Yogurt
- Posts: 61
- Joined: 12 Nov 2012, 09:22
- Noob?: Yes
Re: Perl Help
EternalHarvest wrote: Spawning Task::Timeout with your function should do, like in Actor::setStatus.
Re: Perl Help
Can't use string ("mainLoop_post") as a HASH ref while "strict refs" in use line 104
line 104 -> $taskManager->add(Task::Timeout->new(
object => $self->{statuses}{$handle},
weak => 1,
,#now
seconds => $tick / 1000 - 1,
));
Sorry, i'm new to perl.
line 104 -> $taskManager->add(Task::Timeout->new(
object => $self->{statuses}{$handle},
weak => 1,
,#now
seconds => $tick / 1000 - 1,
));
Sorry, i'm new to perl.
Re: Perl Help
It would be better to display the entire plugin, and not only a part...
But, because you are leaving a blank line, with only the comma?
But, because you are leaving a blank line, with only the comma?
line 104 -> $taskManager->add(Task::Timeout->new(
object => $self->{statuses}{$handle},
weak => 1,
,#now
seconds => $tick / 1000 - 1,
));
Re: Perl Help
Well, lets see if you made the call correctly (since iRO is down at the moment I can't test to see if I'm right or not).
Therefore you will need to define {function} and {stop} (optional), however this also calls: Task::Wait which as as follows:
Meaning you will need to define {seconds} and {inGame} (optional). Finally, it also calls Task::Function which is as follows:
This needs {object} to be defined and {weak} (optional) This also needs object to be placed first.
So I believe a correct call would be:
note: if function isnt a method of a class you can set object to undef (I think anyway).
The function Task::Timeout is as follows:line 104 -> $taskManager->add(Task::Timeout->new(
object => $self->{statuses}{$handle},
weak => 1,
,#now
seconds => $tick / 1000 - 1,
));
Code: Select all
sub new {
my ($class, %args) = @_;
my $function = $args{function};
$args{function} = sub {
&{$function};
($_[0] && $_[0]->isa('Task') ? $_[0] : $_[1])->setDone;
};
my $self = $class->SUPER::new(tasks => [
Task::Wait->new(%args),
Task::Function->new(%args),
], %args);
$self->{stop} = $args{stop};
$self;
}
Code: Select all
sub new {
my $class = shift;
my %args = @_;
my $self = $class->SUPER::new(@_);
$self->{wait}{timeout} = $args{seconds};
$self->{inGame} = defined($args{inGame}) ? $args{inGame} : 1;
return $self;
}
Code: Select all
sub new {
my $class = shift;
my %args = @_;
my $self = $class->SUPER::new(@_);
if (!$args{function}) {
ArgumentException->throw("No function argument given.");
}
$self->{function} = $args{function};
if ($args{object}) {
$self->{object} = $args{object};
Scalar::Util::weaken($self->{object}) if ($args{weak});
}
return $self;
}
So I believe a correct call would be:
Code: Select all
$taskManager->add(Task::Timeout->new(
object => $self->{statuses}{$handle},
function => &somefunction,
seconds => 1,
inGame => 1,
weak => 1
));
Re: Perl Help
Another way is to follow the example of the cases that the same function has been used or go read the comments in the file.
Re: Perl Help
Here's how I am calling it in my current plugin:
Code: Select all
$taskManager->add(Task::Timeout->new(
object => undef,
function => sub{ \&castSkill(272) },
seconds => (((200-$char->{'attack_speed'})/50)+.05),
inGame => 1,
weak => 1
));