mIRC Home    About    Download    Register    News    Help

Topic Options
#120015 - 12/05/05 05:27 PM aliases in scripts
duklaa Offline
Nutrimatic drinks dispenser

Registered: 12/05/05
Posts: 6
I have some aliases defined that I would like to use in remote scripts but I think I am not clear on the syntax.

e.g. My aliases.ini defines
/ca /say California

and then I want to use this in a remote:

on 1:TEXT:where are you from:?:/msg $nick /ca

However this seems to send the string "/ca" instead of executing the alias.

What am I doing wrong?

Top
#120016 - 12/05/05 05:32 PM Re: aliases in scripts
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
Try /ca return California.

Code:
on 1:TEXT:where are you from:?: {
  msg $nick $ca
}

Top
#120017 - 12/05/05 05:52 PM Re: aliases in scripts
duklaa Offline
Nutrimatic drinks dispenser

Registered: 12/05/05
Posts: 6
Thanks. That worked.

However, now I cannot manually type /ca to say "California".

Does this mean that aliases that one uses manually and aliases that one uses in scripts are different? If that's the case, then I think that's where my conceptual confusion arose from.

Top
#120018 - 12/05/05 06:08 PM Re: aliases in scripts
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
No they're entirely the same it's how you wish to use them, that's all.

Just don't use the /SAY command because you're not specifying a target, use the /MSG command.

If you use the /RETURN command as I did earlier you can use a custom identifier for your data.

Code:
alias test { 
  return Testing..
}


//echo -a $test will echo Testing...

You can still use the /ca command/alias in your script if you want to using the $ sign and your alias shows your using the return command to return data with another command (or something along those lines..).

/alias /ca /msg $nick California.

Then have /ca in your On Text event.

One minor note, you don't have to call aliases from the Aliase section of the Remote Editor, you can define your aliases in Remote Scripts where you put the On Text events.

Example:

Code:
alias ca {
  msg $nick California
}


-Andy

Top
#120019 - 12/05/05 06:28 PM Re: aliases in scripts
duklaa Offline
Nutrimatic drinks dispenser

Registered: 12/05/05
Posts: 6
Thanks. I think I understand it better now. But I am still confused about one point:

What I want to do is use an alias two ways:
- to type in the current window, and
- in a remote script.

e.g.,
I want to be able to able to manually type
/ca in a window and have it exand to california, AND
I want to use in a remote script to automatically reply to a question.

If I change the /say to /msg $nick form then it works fine in the remote script but mirc complains "insufficient parameters" when I type /ca in a query window.

Thanks. I appreciate the help in clearing my conceptual confusion.

Top
#120020 - 12/05/05 06:43 PM Re: aliases in scripts
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
you can do something along the lines of:

In alias:

/ca $iif($1,msg $1 California,say California)

Then, in remotes:

on 1:TEXT:where are you from:?: { ca $nick }


Edited by Riamus2 (12/05/05 06:51 PM)
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#120021 - 12/05/05 06:45 PM Re: aliases in scripts
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
Try this.

Code:
alias ca {
  if (%target) { 
    msg $target California 
    unset %target
  }
  else { say California }
}

On *:Text:where do you come from*:?: { 
  set %target $true
  ca
}


When you type /ca manually in any window it uses the SAY command. When it's called from a script it uses the MSG command.

An explanation of how we managed this:

When someone messages us with where are you from? We set a variable with a $true value and triggers our /CA alias. In our /CA alias it checks to see if the variable exists and if it does we use the /MSG command then unsets the variable, so it will never always be /MSG.

When we type /CA manually obviously the variable would be set so after we check to see if the variable exists using an IF statement, we use the else statement to use the say command.

Hope this helps and sheds some light.

Edit: Riamus' way is better to use, more simplistic. laugh
-Andy

Top
#120022 - 12/05/05 06:51 PM Re: aliases in scripts
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
I'm enjoying using $iif's... I've never really used them until recently. smile

duklaa: as an explanation of $iif..

$iif is an if/then/else statement. If the first part is true, do the first command, if it's false, do the second statement):


Example ways to look at the identifier
$iif(if,then,else)
$iif(question,true command,false command)

Note that it would also allow you to use /ca nick and it will allow you to send it to anyone without being in a query window with them. It would also work with /ca #chan as well.

Edit for above: I did change msg $active to say. Forgot about the say command. smile
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#120023 - 12/05/05 07:49 PM Re: aliases in scripts
Kelder Offline
Hoopy frood

Registered: 12/04/03
Posts: 701
Loc: Leuven, Belgium
on 1:TEXT:where are you from:?:/msg $nick $ca
alias ca {
if ($isid) return California
if ($1) msg $1 California
else say California
}


$iif() does the same as an if, but an if does the same too and faster also...

Top
#120024 - 12/05/05 08:04 PM Re: aliases in scripts
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
How is it faster?

Yes, $iif is an if/then/else command as I said. It's just a condensed version of that. For that reason, it should run faster and be cleaner code. If it's not faster, I'm curious as to why.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#120025 - 13/05/05 12:41 AM Re: aliases in scripts
DaveC Offline
Planetary brain

Registered: 26/09/03
Posts: 4230
I would say its the parsing of the line thats taking it longer maybe. But $iif is slower for sure.

example
Code:
/speedtest {
  var %1 = 1
  var %2 = 2
  var %l = 10000
  var %t = $ticks | var %i = %l | while (%i) { !.echo -q blah                                             | dec %i } | echo -st looptime $calc($ticks - %t) | var %r = $calc($ticks - %t)
  var %t = $ticks | var %i = %l | while (%i) { !.echo -q $iif(%1 == %2,blah,blob)                         | dec %i } | echo -st $!iif == $calc($ticks - %t - %r)
  var %t = $ticks | var %i = %l | while (%i) { !.echo -q $iif(%1 != %2,blah,blob)                         | dec %i } | echo -st $!iif != $calc($ticks - %t - %r)
  var %t = $ticks | var %i = %l | while (%i) { !.echo -q blah                                             | dec %i } | echo -st looptime $calc($ticks - %t) | var %r = $calc($ticks - %t)
  var %t = $ticks | var %i = %l | while (%i) { if (%1 == %2) { !.echo -q blah } | else { !.echo -q blob } | dec %i } | echo -st IF (==). $calc($ticks - %t - %r)
  var %t = $ticks | var %i = %l | while (%i) { if (%1 != %2) { !.echo -q blob } | else { !.echo -q blob } | dec %i } | echo -st IF (!=). $calc($ticks - %t - %r)
}


Adjust %l up for more loops if pc speed is still to great to see a difference.

Personally tho on what you used it on I would not have a problem, not like its being called 10000 a second eh?

Top
#120026 - 13/05/05 03:32 AM Re: aliases in scripts
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Interesting. smile

Well, I guess it comes down to how complex the script is and if you want it to be condensed down or not.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top