mIRC Home    About    Download    Register    News    Help

Print Thread
#200626 08/06/08 05:16 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Why is it when you pass variables if one of the middle variables is not set, when passed, that it throws all the remaining variables off? Ex:

{
...
var %small = small ,%big = big
apple %small %medium %big
...
}

alias apple {
echo -s small: %small 1: $1 medium: %medium 2: $2 big: %big 3: $3
}

Displayed result: small: small 1: small medium: 2: big big: big 3:


I registered; you should too.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The /apple alias doesn't know that its parameters came from variables. All it sees are the final values of the parameters, after all evaluations have been performed. Now "%small %medium %big" evaluates to "small <empty> big", ie "small", followed by two spaces, followed by "big".

However, in (almost) all /commands, consecutive spaces in the parameter string are merged into a single space, so the string eventually passed to /apple is "small big", hence $1 = small and $2 = big.

A way to get around this is to call /apple not as a command but as a custom identifier, ie instead of
apple %small %medium %big
use
noop $apple(%small,%medium,%big)
This way $1 = small, $2 = $null and $3 = big.

(you can omit /noop if apple doesn't call /return <value> at any point)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
If a first alias gets called w/o passing variables (they should auto-pass to first alias), when the second alias gets called from within the first alias, variables need to be passed from the original calling code (from first alias), as they aren't automatically passed through the first alias to the second alias, right? Ex:

{
...
var %apple = apple
fruit %size ;other variable being passed
}

alias fruit {
echo -s apple: %apple (variable apple is automatically passed)
shape ;not passing %apple so won't have a value
size %apple ;passing %apple so will have a value
}

alias shape {
echo -s apple: %apple ;%apple won't have a value as it was not passed by alias fruit from the original code
}

alias size {
echo -s apple: %apple ;%apple has a value as it was passed by alias fruit from the original code
}


I registered; you should too.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Local variables (/var) are not automatically passed from one alias to another alias called from the first. /var's are local ONLY to the alias inwhich they are set. If you make another /var with the same name as one in the calling alias, they are separate from each other. Change a value in one alias doesn't affect the other.

Code:

alias First {
var %first = FIRST
echo -a 1.1: %first
second
third %first
echo -a 1.2: %first
}

alias second {
echo -a 2.1: %first
echo -a 2.2: $1
}

alias third {
echo -a 3.1: %first
echo -a 3.2: $1
var %first = THIRD
echo -a 3.3: %first
}



-genius_at_work

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
What about /set? Will /set variables auto transfer into the first called alias? What about when the first called alias calls a second alias, will the second alias auto receive the /set variables that were auto transfered to the first alias?


I registered; you should too.
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
/set variables are global, in that they remain until you /unset them or manually remove them, and they can be used by ALL scripts.

What you're after is probably /set -u. If you use /set -u <var> <value> then that script and all scripts it calls will be able to access the variable.

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Let me clearify something here about what I'm asking. Lets say I have a mIRC variable of $nick in the main code and I call an alias w/o passing $nick to the alias. I'm able to use $nick in the first alias, but if I call a second alias from the first alias, $nick from the original calling code might not get auto-passed through the first alias to the second alias. Is this right?


I registered; you should too.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
$nick is not a variable, it is an identifier. Some identifiers are always available ($me, $ctime, etc), and others are only available within certain events ($nick, $chan, etc). Those event-specific identifiers are available from the event, and all aliases that are called from within that event.

-genius_at_work


Link Copied to Clipboard