mIRC Homepage
Posted By: Matjoeman $chan in an alias in a timer - 27/06/06 05:36 PM
I have a timer that runs an alias where it then does a /msg $chan <text> function. It seems to be ignoring the $chan and trying to msg the first word of the text. /msg chan works in other areas of my script.

Code:
 alias distroles {
  if (%plyrs == 3) {
    set %game 2
    msg $chan |MAFIABOT|Mafia game starting, %plyrs playing, distributing roles.
  }
  else {
    msg $chan |MAFIABOT|Mafia game cancelled, not enough players signed up.
    set %game 0
  }
}
on *:TEXT:!mmafia start:#:{
  if (%game == 0) {
    msg $chan 0,1|MAFIABOT|Starting a game of mafia, type !mmafia in to join.
    set %game 1
    timer1 1 15 [ distroles ]
  }
  else if (%game &gt; 0) /msg $chan 0,1|MAFIABOT|Game of mafia already in progress
}
 

the starting game line works just fine, but after the timer i get this:

* Timer 1 activated
-
-> *|MAFIABOT|Mafia* game cancelled, not enough players signed up.
-
* Timer 1 halted
-
|MAFIABOT|Mafia No such nick
-

so I'm confused
Posted By: landonsandor Re: $chan in an alias in a timer - 27/06/06 06:17 PM
It's because you're not telling it which channel to do it in. Nowhere in the TIMER command are you designating it. Try something like (for example and may not work):

timer1 1 15 [ distroles ] #

and then in the alias, maybe something like this:

msg $1 the rest of it here

This way, the timer fills the alias with the channel and it can be used......... The coding might be off, but Im sure this gets the general idea across.
Posted By: Matjoeman Re: $chan in an alias in a timer - 27/06/06 06:27 PM
ty it works fine now
Posted By: landonsandor Re: $chan in an alias in a timer - 27/06/06 07:27 PM
anytime, glad to be of help smile
Posted By: DaveC Re: $chan in an alias in a timer - 28/06/06 07:17 AM
As already explained to you the $chan value doesnt survive into the timer, so u must pass it to the timer, now while in your case it likely is ok to pass it as $1 it can infact cause problems as expressed to me not long ago. because a channel like #$me well convert to your nick, thus u been pming yourself. (pretty od i know but still there)

also you should NEVER name a timer a number Doubly so the number 1 since that timer is amost always going to already exist.

heres a fix for this
Code:
alias distroles {
  var %chan = $iif($ctimer,$mid($v1,19),$chan)
  if (%plyrs == 3) {
    set %game 2
    msg %chan |MAFIABOT|Mafia game starting, %plyrs playing, distributing roles.
  }
  else {
    msg %chan |MAFIABOT|Mafia game cancelled, not enough players signed up.
    set %game 0
  }
}
on *:TEXT:!mmafia start:#:{
  if (%game == 0) {
    msg $chan 0,1|MAFIABOT|Starting a game of mafia, type !mmafia in to join.
    set %game 1
    timer.!mmafia.start.on. $+ $chan 1 15 distroles
  }
  else if (%game &gt; 0) /msg $chan 0,1|MAFIABOT|Game of mafia already in progress
}


I insert the name of the channel into the timer name at character 19, so when the alias is called it has the $ctimer value and you pull the channel name out of it, if the $ctimer doesnt exist u likely ran the alias your self, so it uses $chan, from there the alias uses the now set %chan value.
© mIRC Discussion Forums