22 Dec, 2008, Brinson wrote in the 1st comment:
Votes: 0
Don't know hardly anything about Perl, but am trying to write a plugin.

Trying to write a rolling plugin that execuites the "roll" command when it sees something below the $target variable.

written this so far by modifying the sample plugin

@array = (30..$target);

foreach (@array) {
$::world->trigger('$_', 'roll', { name => 'sample:misc' });
}


If I manually set $target to a number, it rolls perfectly until it has a number above that one.

I am toying with how to add a command to set $target, yet no matter what I do it doesn't seem to be work.

Looking at sample plugins I thought it would be something like:

sub RollerTarget {
$target = $_[0];
}


But that doesn't work.

Anyone know anything about writing plugins for Kildclient?

I have zero perl knowledge, basically just stabbing in the dark hoping it works.
22 Dec, 2008, Omega wrote in the 2nd comment:
Votes: 0
Target is supposed to be a number correct?
22 Dec, 2008, Brinson wrote in the 3rd comment:
Votes: 0
Yes. I can set it manually in the plugin, but any way I try to set it once the mud is open seems to fail.

tried manually putting in like /$target=50; into the command box to manually set it but it doesn't seem to work either.
22 Dec, 2008, Omega wrote in the 4th comment:
Votes: 0
well, I have no experience with the app its from, but I can tell you this.

but Perl… Oh how I love thee…
Usage RollerTarget(TARGET=>3);
sub RollerTarget {
my %args =(
TARGET=>0,
@_,
);
my $ret_val = $TARGET;
return $ret_val;
}


Thats just how I'd do the RollerTarget function.
As for your inputting, it may want it like /$target=>50 Just an Idea, not sure how the system works itself, but perl can be interesting to say the least. <hugs his tkx perl area editor>
22 Dec, 2008, David Haley wrote in the 5th comment:
Votes: 0
Don't you mean $args{TARGET} or something like that?
22 Dec, 2008, Omega wrote in the 6th comment:
Votes: 0
Yeah, $args{TARGET}

sorry, my bad, been a long day :P

sub RollerTarget {
my %args =(
TARGET=>0,
@_,
);
my $ret_val = $args{TARGET};
return $ret_val;
}
22 Dec, 2008, David Haley wrote in the 7th comment:
Votes: 0
While we're at it, your function doesn't actually do what he wanted, which was to set the 'target' variable…

sub RollerTarget {
# set $target to the passed argument, or 0 if none passed.
$target = shift or 0;
}

Usage:
RollerTarget(123);
22 Dec, 2008, Omega wrote in the 8th comment:
Votes: 0
Actually, his original method does work, $_[0] is a valid method to grab the argument inputted to a subroutine.

shift is another method todo it.

I prefer the setting method that I use in all my apps, which is the example I gave.
22 Dec, 2008, David Haley wrote in the 9th comment:
Votes: 0
The original does indeed set $target to the first argument; the modification defaults it to zero if nothing was provided. The example you gave still doesn't actually set $target, though. It just returns the function argument.
22 Dec, 2008, Omega wrote in the 10th comment:
Votes: 0
Yuppers, mine returns it, as I said, its how I would of done it, meaning I would be setting target outside of that subroutine. but still easy enough to set it.

instead of the return a simple

$target = $args{TARGET};


would do the trick easily enough :) (just remove ret_val)
22 Dec, 2008, David Haley wrote in the 11th comment:
Votes: 0
What's the point of a subroutine that only returns its argument? Eh, anyhow, problem solved…
22 Dec, 2008, Omega wrote in the 12th comment:
Votes: 0
True enough, true enough, didn't think of it that way.. HAHA..

ya got me there :)
22 Jan, 2009, Brinson wrote in the 13th comment:
Votes: 0
Okay, so I never got this to work, and am trying again.

This is my plugin:

package FL_roller;
#: Version: 1.0.0
#: Description: Rolling Plugin for FL
#: Author: Chase Baggett
#

void $world->makepermanent($target);

sub target {
$target = $_;
}

@array = (30..$target);

foreach (@array) {
$::world->trigger('$_', 'roll', { name => 'sample:misc' });
}



If I put a line in like

$target = 50;

it will roll to 50, but I don't want to have to rewrite the plugin each time I roll for a different number, so…I'm trying to get the target subroutine to work.

I input into my text box: /FL_Roller:target(50)

and I get

Perl Error: Undefined subroutine &main::target called at (eval 4) line 1.

Anyone know what I am doing wrong?
22 Jan, 2009, David Haley wrote in the 14th comment:
Votes: 0
Is it intentional that you have one colon, not two? Try: /FL_Roller::target(50)
keep in mind that I know nothing about KildClient… but, to get something in a package, you need two colons.
22 Jan, 2009, Brinson wrote in the 15th comment:
Votes: 0
That was a mistake, yes, but changing it still has the same result.
22 Jan, 2009, David Haley wrote in the 16th comment:
Votes: 0
Note that your package is FL_roller but you are typing FL_Roller.
23 Jan, 2009, quixadhal wrote in the 17th comment:
Votes: 0
DavidHaley said:
What's the point of a subroutine that only returns its argument? Eh, anyhow, problem solved…


That's an API to allow you to pass code refs around, so the caller doesn't have to know what it's calling. From whatever is calling target()'s point of view, it could just as easily be popping up a window to ask the user for a number, or using TCP::CarrierPigeon to get a number from some other site.. slowly.

FWIW, the code above appears to set triggers for all values between 30 and what you pass in. Is that intended? If you pass it a number less than 30, it will do nothing at all, and passing it a big number like 999999 will run far more triggers than you probably want?

I also know nothing about the client app, but it seems like you'd want a trigger to loop, executing your roll command until the output matches a pattern where the result is larger than what you asked for. This seems to be setting up multiple triggers to do the reroll once each?
23 Jan, 2009, David Haley wrote in the 18th comment:
Votes: 0
quixadhal said:
That's an API to allow you to pass code refs around, so the caller doesn't have to know what it's calling.

I have no idea what you mean, Quix, in this context. :wink: I don't think we're dealing with anything having to do with passing code refs around here, unless I'm completely misunderstood something…
23 Jan, 2009, quixadhal wrote in the 19th comment:
Votes: 0
I assumed there was some reason why target would be a subroutine, since if it only interacts with a local variable, it is rather pointless. The problem here, is we don't have the caller's API for writing plugins for this thing. :blues:
24 Jan, 2009, Brinson wrote in the 20th comment:
Votes: 0
The mud I'm making this for will never roll under a 30, hence why 30 is the humber. The plugin seens anything between 30 and X and executes a roll.

The only part I am having difficulty with is setting the variable. The plugin works other than that…

Its weird.
0.0/22