Scripting trouble

Posted by Urthdigger on Sat 20 Mar 2004 02:24 AM — 5 posts, 17,164 views.

USA #0
I hate to ask, but I'm having trouble scripting something, and have been having trouble with it. I'm just trying to make an alias to enable or disable a timer group called peer. The code is as follows.

sub peer (thename, theoutput, toggle)



select case uCase "toggle"
case "ON"
world.EnableTimerGroup "peer", 1
case "OFF"
world.EnableTimerGroup "peer", 0
case else
world.note "******** Timer incorrect *********"
exit sub
end select
end sub

The alias is called ^peer(.*)$ and it calls script peer. I've only gone by what I've read on the site, but I always get type mismatch, or syntaz errors.
USA #1
the three things passed to the sub are two text strings, and then an array. Your last variable (toggle) is an array, thats why you are getting a type mismatch. You'll need to simply use toggle(1) to use the first element.
USA #2
Well, you solved one of my problems. I still can't get it to register that I'm using the correct command. Typing "peer off" just gives my timer incorrect message, and does not disable the timer. And before you ask, I made sure to put the timer in the "peer" group.
USA #3
If you type "peer off" then the variable is " peer", youve got a leading space. You can either adjust your trigger, or your script. Which is better, depends on what else you want to do with it (typing peer with no arguement for example)
Australia Forum Administrator #4
I assume you made the alias a regular expression?

However a simpler alias would be:

Match: peer *
Regular expression: not checked

As this has the space already between "peer" and "*" then the word passed to the script will simply be "on" or "off".

I'm not sure you can use "ucase" in that way, I would have written:


sub peer (thename, theoutput, wildcards)
  select case uCase (wildcards (1))
    case "ON"
      world.EnableTimerGroup "peer", 1
      world.Note "Peer group enabled"
    case "OFF"
      world.EnableTimerGroup "peer", 0
      world.Note "Peer group disabled"
    case else
      world.note "Usage: peer on/off"
  end select
end sub


However more simply again, you can do the whole thing inside the alias without having to use a script file, by doing "send to script", like this:


<aliases>
  <alias
   match="peer *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>  select case uCase ("%1")
    case "ON"
      EnableTimerGroup "peer", 1
      Note "Peer group enabled"
    case "OFF"
      EnableTimerGroup "peer", 0
      Note "Peer group disabled"
    case else
      note "Usage: peer on/off"
  end select
</send>
  </alias>
</aliases>