PDA

View Full Version : Lich Script question - skinwatcher.lic



Van
12-20-2005, 12:35 PM
The default install folder contains a sample script "skinwatcher.lic" and while I"m reading through through all of the documentation provided, I'm having a hard time interpreting some of the loop.

What is this portion doing:

"skinname = itemname.slice(/[^\s]+(?=\.)/)"

I'm following the general idea where it's defining the variable "skinname", but the itemname.slice( stuff here ) is what confuses me. The forward slashes "/" are defining the string as a regular expresion, but what is the "^", and "\", and the "s" doing?

The first part of the loop is as follows:

loop { itemname = matchfind "You skinned the [^,]+, yielding ?"; skinname = itemname.slice(etc...

nocturnix
12-20-2005, 05:32 PM
Regular expressions are used to quantify, organize, and arrange text strings...

So without knowing what the syntax is for the LICH regular expression engine, i'm guessing that that piece of code is determining what skin is yielded from skinngin the critter your hunting, then storing it in a variable to use later for stowing/bundling etc.

Where can i find Lich? Sounds cool.

Tagu
12-20-2005, 09:46 PM
I'm not the best with regex yet, but let me see if I can't make it a little clearer on that one.

(for the record, I can't seem to get a backslash to stay in the post here, so everywhere you see a tilde, replace it with a backslash)

/[^~s]+(?=.)/)

the / and / mark a regular expression
the [ and ] create a class of characters, meaning you'd like to match or not match whatever is in the brackets.
the ^ compliments the class, meaning you want to match anything except the listed character
~s is the escape character for a white space, so you're looking to match anything except a white space

so [^~s] matches any character that's not a white space. the + after it means it has to match at least one character to be valid

the (?=.) is a positive lookahead assertetion, forcing the expression to end with a period.


Hope that clears that up some.

Van
12-21-2005, 01:23 PM
Yea, that cleared it up...

It's basically matching "backwards" from the "." until it hits a "blank space", then passing that as "#{skinname}" in the "fput".

Tagu
12-21-2005, 10:10 PM
Well, without pulling the lich documentation, I'm not sure what slice does. The regex part of it is pulling the skiname to the end of the line, ignoring any spaces. I'm guessing slice just takes the first returned set of characters, but I don't know for sure.

Van
12-22-2005, 09:47 AM
I'm think .splice is similar to .split, which takes a string and splits it into an array. But it would seem that something like .splice.last would needed for that to work in this example.

I'm still sort of lost on this. I thought I had it, but now I don't think it's actually matching in "reverse" as I stated.

Shaelun
12-22-2005, 07:26 PM
You people are getting good at this stuff... :)

Everything Tagu said is right, first of all.

Second of all, calling .slice on a string 'slices out' the portion of the string that matches. So it's isolating a piece of the line.

The documentation is pretty bad (recently made a document listing the more useful Lich-specific commands, but it's still somewhat incomplete). Sorry about that; I'm coming to realize it's pretty silly of me to expect people to know stuff w/o my coming out and saying it. So that's what this is: Lich is more or less a Ruby interpreter -- that means any tutorial you see online for the 'Ruby' language *fully* applies to Lich scripts. Here's one that doesn't assume you already know how to program (like so many others seem to do):

http://pine.fm/LearnToProgram/

Just click the links on the left for the tutorial.