mIRC Home    About    Download    Register    News    Help

Print Thread
Simple loop using user defined var #219941 03/04/10 03:05 AM
Joined: Jan 2010
Posts: 10
O
oddvent Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Jan 2010
Posts: 10
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!

Re: Simple loop using user defined var [Re: oddvent] #219944 03/04/10 03:48 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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
    }
  }
}

Re: Simple loop using user defined var [Re: Horstl] #219945 03/04/10 03:53 AM
Joined: Jan 2010
Posts: 10
O
oddvent Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Jan 2010
Posts: 10
Horstl again i must express my gratitude. You are always there with a hasty reply and i appreciate it greatly..

Thank you!

Re: Simple loop using user defined var [Re: oddvent] #219947 03/04/10 04:19 AM
Joined: Jan 2010
Posts: 10
O
oddvent Offline OP
Pikka bird
OP Offline
Pikka bird
O
Joined: Jan 2010
Posts: 10
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

Re: Simple loop using user defined var [Re: oddvent] #219956 03/04/10 06:08 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Re: Simple loop using user defined var [Re: oddvent] #219978 03/04/10 04:19 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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).


Invision Support
#Invision on irc.irchighway.net