|
danr62 Beginner
Joined: 17 May 2003 Posts: 20 Location: USA
|
Posted: Mon Jun 30, 2003 12:43 am
More scripting help needed |
Just a question, is it possible to match arguments against wildcards, for instance
#alias bleh {#if ((%1 = %w) & (%2 = %n) {#echo First argument is a word, second argument is a number} {#echo Incorrect syntax}
Well if I do that it only comes out true if one or both arguments are null, is there another way to acomplish the same thing? |
|
|
|
Jah Wanderer
Joined: 11 Oct 2000 Posts: 52 Location: Sweden
|
Posted: Mon Jun 30, 2003 12:46 am |
isnt number %d ?
|
|
|
|
danr62 Beginner
Joined: 17 May 2003 Posts: 20 Location: USA
|
Posted: Mon Jun 30, 2003 4:11 am |
hmm, so it is, but that wouldn't work for this in any case, I figured out what I need, and that's the function %isnumber(), however, now I have yet another problem. Here's what code I have
#if ((!(%null( %1)) & (%isnum( %1))) & (%null( %2) | !(%isnum( %2)))) {
#additem vials %1
#if %null( %2) {} {#if %ismember(%2,
"health|mana|levitation|immunity|venom|speed|caloric|restoration|empty") {
#addkey vlist %1 %2
#additem %2 %1
} {#echo SYNSTAX: ADDVIAL <number> ~[type]}}
} {#echo SYNTAX: ADDVIAL ~<number> ~[type]}
Now, if I type addvial 1, it should add '1' to the @vials variable, which is not happening(it doesn't echo the text, it just does nothing), second, I should be able to type addvial 1 health to add a '1' to the variable @vials, add the key '1=health' to the variable vlist, and add the item '1' to the variable @health. Instead, I get the error message. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Jun 30, 2003 7:16 am |
Instead of using undefined parameters, use %numparam to determine how many parameters there are. Abbreviated function names (%isnum) are not supported.
#TR {#IF ((%numparam() = 1) AND %isnumber( %1)) {#ADDI vials %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]};#IF ((%numparam() = 2) AND %isnumber( %1) AND %ismember( %2, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {#ADDI vials %1;#ADDK vlist %1 %2;#ADDI %2 %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]};#IF ((%numparam() = 0) OR (%numparam() > 2)) {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]}} |
|
|
|
danr62 Beginner
Joined: 17 May 2003 Posts: 20 Location: USA
|
Posted: Mon Jun 30, 2003 9:38 am |
The above code does not work. The basic reason is that it runs all three checks, if any prove to be false, which at least one always will, it prints out the error statement, if more than one prove to be false, it prints the statement more than once, what we need is a way to make sure only the correct checks are made, the way to do this is with the #case command
#IF ((%numparam() = 0) OR (%numparam() > 2)) {#case %numparam() {#if %isnumber(%1) {#ADDI vials %1} {#ECHO SYNTAX: ADDVIAL ~<number> ~[type]} {#IF ((%numparam() = 2) AND %isnumber( %1) AND %ismember( %2, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {#ADDI vials %1;#ADDK vlist %1 %2[blue];#ADDI [blue]%2 %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]}} |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Jun 30, 2003 4:19 pm |
Ack, good catch. I try to avoid nesting #IFs because I find it difficult to keep track of which condition I'm working with when I'm several levels deep. But, some nesting is necessary this time. Your script won't work because you've started by excluding 1 or 2 params, but then go to #CASE. That means you'll never use the first two statements from #CASE, unless you have at least 4 parameters (which should give you the error message instead).
#AL addvial {#IF (%numparam() = 1) {#IF (%isnumber( %1)) {#ADDI vials %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]}};#IF (%numparam() = 2) {#IF (%isnumber( %1) AND %ismember( %2, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {#ADDI vials %1;#ADDK vlist %1 %2;#ADDI %2 %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]}};#IF ((%numparam() = 0) OR (%numparam() > 2)) {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~]}} |
|
|
|
danr62 Beginner
Joined: 17 May 2003 Posts: 20 Location: USA
|
Posted: Mon Jun 30, 2003 11:36 pm |
I actually wrote that one wrong up there, I wasn't looking at zmud when I did it, what my real code looks like is this
#IF ((%numparam( ) = 0) OR (%numparam( ) > 2)) {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~] 3} {#case %numparam( ) {#IF %isnumber( %1)) {#ADDI vials %1} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~] 1}} {#if (%isnumber( %1) AND %ismember( %2, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {
#ADDI vials %1
#ADDK vlist %1 %2
#ADDI %2 %1
} {#ECHO SYNTAX: ADDVIAL ~<number~> ~[type~] 2}}}
The first #if statement checks whether you put too many or too few parameters, if you did, prints the error message, if not, executes the #case depending on whether there were one or two parameters, works perfect. Now all I need to do is make sure it replaces vials already registered in the various variables |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Jul 01, 2003 1:31 am |
Yep, that will work. My revised script does pretty much the same thing, in a slightly different order. Glad I was able to help you find a solution of your own.
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|