|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
I'm not sure I called it the right term, but how do I call a sub routine from another part of the script; what about passing variables?
Let say I have a script and several places in the script it does the same process, how do I set up a sub routine and call it from different places from within the main part of the script, with variables?
I registered; you should too.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
In mIRC this is usually referred to as using aliases An alias can be written in the Aliases tab, or in the Remotes tab The difference between them, is the fact that an alias in the Remotes tab must start with the word alias.
You call an alias by using it's name.
Read up in /help aliases for more details.
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
I understand alais in the alais tab, but not in remotes.
Would this be a proper example in remotes:
alais greet { msg %nick hello! msg %chan %nick $+ , welcome to %chan $+ ! }
on *:JOIN:#:{ set %nick $nick set %chan $chan $greet }
I registered; you should too.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
close alias greet {
msg %nick hello!
msg %chan %nick $+ , welcome to %chan $+ !
}
on *:join:#:{
set %nick $nick
set %chan $chan
greet
}
Alternatively you could use alias greet {
msg $1 hello!
msg $2 $1 $+ , welcome to $2 $+ !
}
on *:join:#:{
greet $nick $chan
} Note that some identifiers, can be used in aliases directly, but I find it easier to pass them even if it's not necessary. You would use $greet(comma separated parameters) if you had information in the alias that was being returned to the calling routine.
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
Thanks.
Where would the '$greet($var1,$var2)' go? Would it be used to call the alias or at the end of the alias?
I registered; you should too.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
First, it's called "alias", not "alais". Second, why do you stick with the custom identifier? Since your alias doesn't return a value, you should just use /greet (or just greet, without the slash, since the slash is not needed in scripts), not $greet(). RussellB showed you two ways of doing it, both including passing information that you don't really need to pass to the alias. The following is how I'd do it. I've also included some changes that reflect better IRC practice. I understand that your current script may just be a test, but the following is good to know anyway: - In automated messages, you should use /notice, not /msg. The official IRC protocol document states this and its advice should be taken. Apart from the possibility of /msg triggering other automated messages, users will be annoyed if whenever they join any channel you are in, they have a query window pop up in their face. /notice's are far less intrusive.
- I included the ! prefix in on JOIN, so that the event doesn't trigger on yourself.
- I changed the target # to #yourchannel. This one's really important. You do not want this to trigger to every channel you are in (unless you are only in your own channels - created by you). If channel operators notice that you run such a script, they will most probably ban you.
alias greet {
notice $nick Hello $nick $+ , welcome to # $+ !
}
on !*:join:#yourchannel:{
greet
}
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
I appreciate your help and I was wanting to know how to do both ways for future reference.
I registered; you should too.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
An important difference between aliases called as commands (/greet) and aliases called as custom identifiers ($greet) (apart form the fact that the latter makes sense only if it returns a value, via /return) is that custom identifiers cannot start a new line/command. Every line in mirc is considered a command. Having something like $greet on its own would make mirc execute the command /foo, where "foo" is whatever $greet returns. This is not what you usually want: the return value of a custom identifier is meant to be used not as a command but as input to some other mirc command (or another identifier), ie it serves as a parameter to something else.
You can get an better idea of all this (and more) by reading the page that comes up if you type /help aliases. That page contains all the basics of mirc scripting and is absolutely necessary, if you are going to script anything.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
I've been reading that help file, as you and others have asked, but it doesn't give ALL the answers and in most cases it does NOT give very many, if ANY examples.
I registered; you should too.
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
I registered; you should too.
|
|
|
|
|