mIRC Homepage
Posted By: duklaa aliases in scripts - 12/05/05 04:27 PM
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?
Posted By: SladeKraven Re: aliases in scripts - 12/05/05 04:32 PM
Try /ca return California.

Code:
on 1:TEXT:where are you from:?: {
  msg $nick $ca
}
Posted By: duklaa Re: aliases in scripts - 12/05/05 04:52 PM
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.
Posted By: SladeKraven Re: aliases in scripts - 12/05/05 05:08 PM
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
Posted By: duklaa Re: aliases in scripts - 12/05/05 05:28 PM
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.
Posted By: Riamus2 Re: aliases in scripts - 12/05/05 05:43 PM
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 }
Posted By: SladeKraven Re: aliases in scripts - 12/05/05 05:45 PM
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
Posted By: Riamus2 Re: aliases in scripts - 12/05/05 05:51 PM
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
Posted By: Kelder Re: aliases in scripts - 12/05/05 06:49 PM
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...
Posted By: Riamus2 Re: aliases in scripts - 12/05/05 07:04 PM
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.
Posted By: DaveC Re: aliases in scripts - 12/05/05 11:41 PM
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?
Posted By: Riamus2 Re: aliases in scripts - 13/05/05 02:32 AM
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.
© mIRC Discussion Forums