|
kopf1988 Beginner
Joined: 19 Jun 2007 Posts: 23
|
Posted: Fri May 15, 2009 10:36 pm
What is %-1? |
I'm trying to study some old scripts, but I can't figure out the %-1 here. Is there a meaning to this that I don't know about? It would help me a bunch :) Thanks!
#if (%numitems(@todo_list) > 0) {todo_list = %concat(@todo_list, "|%-1")} {todo_list = "%-1";#if (%numitems(@todo_list) + %numitems(@todo_free) == %numitems(%-1)) {i_scan_todo}} |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri May 15, 2009 11:01 pm |
The minus sign in front means to fetch all arguments starting with the first one. For example, if you had an alias called "test" and you called it with:
test this is a test
then you get the following variables:
%1 = this
%2 = is
%3 = a
%4 = test
%-1 = this is a test
%-2 = is a test
%-3 = a test
%-4 = test
Now, in CMUD, there is also the %param and %params functions. %param(n) is equal to %n and %params(n) is equal to %-n. So using %params(1) would be the proper new syntax to use instead of "%-1".
The other problem is with the "%-1" syntax. The " double quotes prevent any variables from being parsed within them (which is a change from zMUD). So the %-1 isn't going to be expanded...the "" cause CMUD to treat it as a literal string value.
So your completed and updated script would be:
Code: |
#if (%numitems(@todo_list) > 0) {
todo_list = %concat(@todo_list, "|", %params(1))
} {
todo_list = %params(1)
#if (%numitems(@todo_list) + %numitems(@todo_free) == %numitems(%params(1))) {i_scan_todo}
} |
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri May 15, 2009 11:06 pm |
Edit: Ninja'd (noticed quite a bit later, apparently).
%-1 means take the first parameter and everything after it. %-2 would be take the second parameter and everything after that, and so forth.
For instance, say that I had a command like:
showitem channelname itemnumber message I want to send
where showitem was the alias. I might set it up like this:
#ALIAS showitem {#EXEC %concat(%1, %-3," Item: ",%2)}
It's a contrite example, but here's how it would work:
showitem barter 3 Hi! This is my message! --> barter Hi! This is my message! Item: 3
To break down parameters:
showitem (param1)barter (param2)3 (param3)Hi! (param4)This (param5)is (param6)my (param7)message![/code]
So, %-1 would be "barter 3 Hi! This is my message!"
%-2 would be "3 Hi! This is my message!"
%-3 would be "Hi! This is my message!"
and so forth.
Hope that helps. Might have been more information than you were looking for, though.
Charneus |
|
|
|
kopf1988 Beginner
Joined: 19 Jun 2007 Posts: 23
|
Posted: Sat May 16, 2009 7:01 am |
Thanks, that DOES help!
|
|
|
|
Mixsel Wanderer
Joined: 02 Feb 2003 Posts: 99 Location: Seattle, Wa
|
Posted: Sat May 16, 2009 12:46 pm |
Nice explanation Zugg, always sorta wondered what that does,
for some reason when it's explained that way I get it heh. |
|
_________________ Spin |
|
|
|
kopf1988 Beginner
Joined: 19 Jun 2007 Posts: 23
|
Posted: Sun May 17, 2009 12:01 am |
I assume that affects everything, so I'll have to change:
#priority {temp_list = %null;#forall {%-1} {#if (!%ismember("%i", @todo_list)) {#additem temp_list {%i}}};#if (!%null(@temp_list)) {do @temp_list}}
to:
#priority {temp_list = %null;#forall {%-1} {#if (!%ismember(%i, @todo_list)) {#additem temp_list {%i}}};#if (!%null(@temp_list)) {do @temp_list}}
right? Looking through the documentation I'm pretty darn sure, so nevermind :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun May 17, 2009 1:50 am |
Yup. "string" in CMUD is unambiguously a literal string, and will appear exactly as you typed it, no matter what special characters it contains.
|
|
|
|
kopf1988 Beginner
Joined: 19 Jun 2007 Posts: 23
|
Posted: Sun May 17, 2009 3:03 am |
Thanks! Alright, another question: @dbname.keys doesn't seem to do what it might have in ZMud. Pointers?
Edit: or maybe it was replaced with %dbkeys(dbname). :) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun May 17, 2009 4:15 am |
@dbname.keys was never a thing as far as I can remember. %dbkeys is new and returns a list of the keys in a variable. @dbname.keyname still returns the value of a key provided it's not no special characters in it; %db(@dbname,"keyname") picks up there, same as always.
|
|
|
|
kopf1988 Beginner
Joined: 19 Jun 2007 Posts: 23
|
Posted: Sun May 17, 2009 6:32 pm |
Fang Xianfu wrote: |
@dbname.keys was never a thing as far as I can remember. %dbkeys is new and returns a list of the keys in a variable. @dbname.keyname still returns the value of a key provided it's not no special characters in it; %db(@dbname,"keyname") picks up there, same as always. |
That's odd - the old Acropolis calls on it... a lot it seems. Maybe once I change these it'll start working. Any hints what this is supposed to do:
#forall {%params(2)} {
#delkey %1 {%i};
#delitem %1.keys {%i}
}
Edit again: Maybe it's the name of an item in %1 that is itself a list. Heh. |
|
|
|
|
|