|
romciom Beginner
Joined: 15 Oct 2002 Posts: 10 Location: Poland
|
Posted: Wed Sep 10, 2003 6:57 pm
Capturing into variable |
Hello!
I've made a simple alias which allows me to attack targets more quickly:
#IF %1 {kill %-1;#VAR killtarget "%-1"} {kill @killtarget}
When I type "k guard" it works well, puts "guard" inside a variable and then when i type "k" it adds guard automaticaly.
But when I type something like "k blue-eyed warrior" it does not put "blue-eyed warrior" into variable. It works that whay always when a minus sign appears.
I guess it's something simple, but I can't find it out.
Can anyone help? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Sep 10, 2003 10:31 pm |
What did it put into the variable? Nothing at all? "blue-eyed"? "warrior"? I imagine your frustration stems from the syntax you used in the #IF. Without bracing of some kind (in the case of the #IF command's condition, this would be parentheses), ZMud divides everything command-related by spaces. Therefore, your #IF statement evaluates to:
#IF blue-eyed warrior {kill blue-eyed warrior;#VAR killtarget "blue-eyed warrior"} {kill blue-eyed warrior}
The stuff in green is safe from syntax since it's just a command going to the mud, and the %-1 you used ensures that everything is captured. The stuff in blue explicitly forces ZMud to consider "blue-eyed warrior" as one entity, so we are reasonably sure that the KillTarget variable will indeed contain that phrase. However, the part in red is definitely confusing to ZMud. One of the words is obviously the condition, which would always evaluate to true when an argument is supplied, and that means the other must be the true-condition code-block. Since the code-block is not recognizable as such due to missing curly braces, ZMud probably takes the safe road and does nothing, or it tries its best and comes out wrong. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Sep 11, 2003 7:58 pm |
You should also have a problem when you try to use "k" by itself. In that case you get:
#IF {kill ;#VAR killtarget ""} {kill @killtarget}
Now, there is no condition and #IF will do nothing.
The correct way to do this is with %numparam(). This function returns the number of parameters used with an alias, including 0 if there's none.
#IF (%numparam() > 0) {kill %-1;#VAR killtarget {%-1}} {kill @killtarget} |
|
|
|
romciom Beginner
Joined: 15 Oct 2002 Posts: 10 Location: Poland
|
Posted: Sat Sep 13, 2003 12:32 pm |
Works just great, thanks!
|
|
|
|
|
|