mIRC Homepage
Posted By: oddvent Simple loop using user defined var - 03/04/10 03:05 AM
Hi again. I made a script to count to 5. this is because i only have a basic knowledge of remote scripts. here it is


on *:TEXT:!5:#: {

var %i = 1
while (%i <= 5) {

msg #channelabc %i
inc %i

}
}


But what i would rather is to have the script works as follows:

instead of !5 the user could use !countto 5 and it would output 1,2,3,4,5 on each line.

so that it would also work for !countto 10 or !countto 123 etc.

Once i know how to do this, it will open many more doors in mirc scripting for me.

Thank you for all helped given!
Posted By: Horstl Re: Simple loop using user defined var - 03/04/10 03:48 AM
Have a look at the $N identifiers (/help $1-). $1 is the first word, $2 the second word etc.
Example:
Code:
; "&" is a wildcard for a word
on *:text:!countto &:#: {
  ; only count if the second word is a valid number
  if ($2 isnum 1-) {
    var %a = 1, %b = $2
    while (%a <= %b) {
      msg # %a
      inc %a
    }
  }
}
Posted By: oddvent Re: Simple loop using user defined var - 03/04/10 03:53 AM
Horstl again i must express my gratitude. You are always there with a hasty reply and i appreciate it greatly..

Thank you!
Posted By: oddvent Re: Simple loop using user defined var - 03/04/10 04:19 AM
What if i have multiple Wildcards though, for example:


on *:text:!test &:#:, &:#: {
var %a = $2
var %b = $3
msg # %a
msg # %b
}


how would that work. they are just plain text strings. thanks
Posted By: RusselB Re: Simple loop using user defined var - 03/04/10 06:08 AM
Please see my response to your other post. Additionally, in future, I recommend that you attempt to keep related posts together, rather than having several small posts on basically the same problem.
Posted By: Riamus2 Re: Simple loop using user defined var - 03/04/10 04:19 PM
Keep in mind that the use of & without using any other wildcards will prevent it from triggering with more words.

!test &

That means it will trigger if you have !test followed by a single "word". It won't trigger just for !test and it won't trigger from something like !test this and this. So you'll never have a $3 in your example. & is used when you know how many "words" there will be, but the words can change and you want it only to trigger when the exact number of words are there. Example: !test & & will trigger with !test followed by 2 words (no more, no less).
© mIRC Discussion Forums