 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sat Jul 19, 2008 2:11 am
Are \w and \d considered in params? |
For aliases, if I had an alias... say...
#al "set target" \d { } { }
And I used the %params command in addition to %0 in this example, what would happen?
set target 2 Tryiac
Would %0=2 and
%params=Tryiac? |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jul 19, 2008 3:04 am |
Wasn't aware you could use multiple names delimited by spaces in aliases. However, the answer to your question is no. %1 would be 2 and %-2 would be Trylac and anything else that followed behind it. If it's always one word, just use %2.
Charneus |
|
|
 |
benjunmun Beginner
Joined: 23 Feb 2002 Posts: 23
|
Posted: Sat Jul 19, 2008 3:17 am |
You've got a few concepts confused here.
First of all, \w and \d only apply to triggers. An alias automatically splits up its arguments by spaces in to %1, %2 etc. Second, as far as I can tell you can't have an alias with a space in it. Also, there is no %0. The %num variables start at 1.
Now, as for what you are trying to do, there are several ways to go about it. If you want to do this as an alias, you could do something like:
#al set_target {#echo %1, %-2}
(%-2 is equivalent to %params(2))
Or, you could use an #oninput trigger to do more precise pattern matching:
#oninput {^set target (\d+) (.*)$} {#noinput;#echo %1, %-2} {} {regex}
This allows you to use the \d syntax if you want to
(remember that this is a regex pattern, not a regular zscript pattern which would be: "^set target (%d) (*)$") |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sat Jul 19, 2008 3:58 am |
I've had problems with - numbers, which is why I used params. So, you went through a lot of explaining that never really answered my question. It really isn't that hard and I'm not an idiot. The question is whether or not %params will include the two if I tell it there will be a number before the rest of the argument. I clearly recall being able to place something in the alias for a capture, though it was likely zscript and not regex, so (%d) instead or something.
|
|
|
 |
benjunmun Beginner
Joined: 23 Feb 2002 Posts: 23
|
Posted: Sat Jul 19, 2008 4:35 am |
Sorry if that sounded condescending. What exactly are the problems you're having with numbers? An alias will automatically pick up each of the arguments - there is no specific argument to tell it to capture something.
If you have an alias:
#alias test
and call it like this:
test 1 tree
then:
%1 = 1
%2 = tree
%-1 = 1 tree
%params = 1 tree
If you're trying to force something to be a number, try %number or %eval
-Ben |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jul 19, 2008 1:27 pm |
It doesn't appear that you specifically need the params for anything other than setting the target. However, using the alias, you'll be able to set a negative number and a word. Like ben said, %1 will always be the first object after the alias name (in this case, 2) and %-2 will always be everything from object 2 on. So, if you had "set_target -2 big fat meanie", then the following would be set:
%1=-2
%2=big
%3=fat
%4=meanie
%-1=-2 big fat meanie
%-2=big fat meanie
%-3=fat meanie
And so forth.
If you REALLY want to be picky about it, use the oninput trigger. I'd set it up as:
#ONINPUT {^set target (%n) (*)} {#NOINPUT;targetnum=%1;targetname=%2}
Then, set target will only fire if the first param is a number, regardless if it's negative or not. Just some suggestions.
Charneus |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sat Jul 19, 2008 2:21 pm |
benjunmun wrote: |
Sorry if that sounded condescending. What exactly are the problems you're having with numbers? An alias will automatically pick up each of the arguments - there is no specific argument to tell it to capture something.
If you have an alias:
#alias test
and call it like this:
test 1 tree
then:
%1 = 1
%2 = tree
%-1 = 1 tree
%params = 1 tree
If you're trying to force something to be a number, try %number or %eval
-Ben |
Thank you, that's what I wanted to know right there. Now, I could use %-2, but I had issues with it before. I suppose I'll try it out and see what happens.
@Charneus - I'll try the %-2 and see how it goes, otherwise I'll look at both oninput triggers.
Edit:
Well, I tried it, but I'm getting an unmatches braces error. Also, relooking at your posts, I was more grumpy last night than anything and I apologize. Anyways...
Quote: |
#al set_target {
$target=%1
#switch($target)
(1) {@target1=%-2;#say Target 1: %-2}
(2) {@target2=%-2;#say Target 2: %-2}
(3) {@target3=%-2;#say Target 3: %-2}
{#say Invalid number argument} } {General Aliases}
|
Code: |
#al set_target {
$target=%1
#switch($target)
(1) {@target1=%-2;#say Target 1: %-2}
(2) {@target2=%-2;#say Target 2: %-2}
(3) {@target3=%-2;#say Target 3: %-2}
{#say Invalid number argument} } {General Aliases}
|
I'm getting an unmatches braces error, but, as you can see here, they're all matched up properly. |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jul 19, 2008 3:08 pm |
That could be SO much cleaner.
#alias set_target {#IF %isnumber(%1) {#VAR %concat("target",%1) %-2;#SAY Target %1: %-2} {#SAY Invalid number format.}}
Also, again, if the target is ALWAYS one word, just use %2. If you'll have a target like Trylac the Wimpy, then use %-2. Don't overcomplicate things. :p
Charneus |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sat Jul 19, 2008 3:16 pm |
It won't always be one word, I'm just using one word for the test. I was told switch statements were better than if statements for this sort of thing, could you tell me why you went with the if statement instead? Also, what's with this #var concat, is it creating dynamic variables based on need? What happens when the variable changes but still exists, does it create a new one, or?
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jul 19, 2008 4:04 pm |
SWITCH statements are better to use than nested if statements. Instead of using if then elseif then elseif then else, you'd use switch. Also, it would be better if all your commands following the switches were different, like switch target1 kill target, target2 slap target, target3 bash target and so forth.
The concatenation is because you're using the same variable name overall, just following it with whatever number you input. Unless there's a bug, it'll just overwrite the variable there. So essentially, what it's doing is this:
Set_target 3 bird
Variable target3 bird
Set_target 3 rabbit
Variable target3 rabbit
And so on. It just takes the number and places target in front of it. That way, you don't have to stress out your fingers typing the same thing over and over. :p
Sorry if this seems contrite. I'm on my blackberry (have been the duration of this post) and I hate having to type out the symbols. :p Hopefully, you'll get what I'm saying. If not, I'll explain a bit more next post. Even if I have to do it from my bb.
Charneus |
|
|
 |
|
|