mIRC Home    About    Download    Register    News    Help

Print Thread
#83345 18/05/04 02:54 AM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
I thought someone else was going to post this, but oh well.

/msg #chan1,#chan2,etc should display your message in all these channels just like /msg or /amsg.

Just food for thought.


You won't like it when I get angry.
#83346 18/05/04 08:30 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

until it (may or may not) get added, you can use the following:
Code:
  
msgchans {
  var %msg = $2-
  tokenize 44 $1
  while ($0) { if $left($1,1) == $chr(35) { echo -a $1 %msg } | tokenize 32 $2- } 
}

Usage: /msgchans #chan1,#chan2,#chan3 message

Note that you can rename this alias to whatever name you want, though if you change it to "alias msg", note that it will override the normal /msg command, unless you do /!msg, which will use mIRC's default /msg command.

Greetz


Gone.
#83347 18/05/04 08:31 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

until it (may or may not) get added, you can use the following:
Code:
  
msgchans {
  var %msg = $2-
  tokenize 44 $1
  while ($0) { if $left($1,1) == $chr(35) { msg $1 %msg } | tokenize 32 $2- } 
}

Usage: /msgchans #chan1,#chan2,#chan3 message

Note that you can rename this alias to whatever name you want, though if you change it to "alias msg", note that it will override the normal /msg command, unless you do /!msg, which will use mIRC's default /msg command.

Greetz


Gone.
#83348 18/05/04 09:28 AM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
Thank you for this brilliant inspiration which I would have never thought up myself.

It is rather inefficient to continually tokenize the string, and you never actually send a message to the channel (or were you just pointing out the echo -a to display what it's doing?). You may as well just do:

Code:
alias msg { 
  var %a 1,%b 
  while $gettok($1,%a,44) { 
    %b = $ifmatch 
    !.msg %b $2- 
    echo -t %b < $+ $nick(%b,$me).pnick $+ > $2- 
    inc %a 
  }
}


(And yes there are tonnes of ways such as the multple /dec applications instead)


You won't like it when I get angry.
#83349 18/05/04 09:43 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
alias msg var %msg = $$2- | tokenize 44 $1 | !msg $* %msg

grin

#83350 18/05/04 10:50 AM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
lol, <3 Online


You won't like it when I get angry.
#83351 18/05/04 11:45 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Oh [censored],

I had no idea that I posted twice! I have the habit of getting on the mIRC msg boards, first thing when I get up, so that I waken up whilst browsing the boards, before studying.

Maybe in the future I should do something else first, and check the boards in the afternoon or something.

Indeed, I used the echo -a for testing purposes cuz I didn't connect to a server, but I did wanted to see if the code works.

Btw I only posted that as a means to help you, no need to be offensive. And if you (and your tone implies it) feel that you are l33t enough to script something like that yourself, then why don't you...
As for the continuous tokenizing: you ought to benchmark things first (I thank qwerty for pointing that out) before saying things. I've benchmarked the two alias following, and the result is that they are equally fast (or a neglictable difference):

Code:
test1 {  
  var %t = $ticks
  tokenize 32 $str(lol $chr(32),50)
  while ($0) { echo -a $1 | tokenize 32 $2- }
  echo -a $calc($ticks - %t)
}
 [color:red]  [/color] 
test2 {
  var %t = $ticks, %string = $str(lol $chr(32),50), %x = $numtok(%string,32)
  while (%x) { echo -a $gettok(%string,%x,32) | dec %x }
  echo -a $calc($ticks - %t)
}

Result for both aliases: 62

I'm not saying there wouldnt be a difference if you would benchmark it for like 10000 items or something, but that isn't an issue in this case, since we are making an alias that sends a msg to a number of channels. And I think 50 channels is already way more than whatever amount of channels will be used with this alias. Besides you'd end up with *string too long* anyways if the amount of channels gets too big.

Now to stop my rant, the line of code that Online posted is the most efficient of all, nice smile
However , by using that method, he is inable to check whether the words in the tokenized string are actually channels. So when a person forgets to put the #, itwill try to msg to a nickname, rather than a channel, whereas in my example it will ignore it and move on to the next channel.

Greetz

Last edited by FiberOPtics; 18/05/04 11:57 AM.

Gone.
#83352 18/05/04 12:01 PM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
By all means I wasn't trying to sound too offensive, although I have been through this a lot in the last couple of days with helpers in my own scripting channels providing "crappy" code.

And yes I was referring to the mass use of tokenize, since it can be much, much slower. In this case, tests returned that the tokenize'd alias is twice as slow as the other variant (31ms and 15ms respectively), that is why I was inferring that it is indeed slower.
Although in this case, as you pointed out, it doesn't make that much of a difference (only 16ms), I was just pointing out that that style of looping is a very bad coding habit.

/tokenize should never be used in looping where another way exists.


You won't like it when I get angry.
#83353 18/05/04 02:18 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Heh,

1. I don't see why you would refer to mass tokenizing, whilst in this example this is not a case of mass tokenizing. If it were, then I wouldn't use tokenize myself, as I usually use a variable and then /inc or /dec.

2. I've tested those two test aliases on my own computer now (I was at the computer labs of my university at the time i posted those test1 and test2 aliases) and I still get a maximum difference in speed of 1 ms, in favor for the tokenized way. Even if it would be 50 ms different, I hardly doubt anyone wanting to msg something to a couple of channels, is going to mind the 50 ms. Note that I do think speed is a very important aspect of code, and I'm usually even too obsessed with it, trying to make the fastest working script. It's just that in certain cases, speed isn't an issue...

3. What I posted was not crappy code at all. It was simply an alternative way of achieving something, without having to set any variables to do the loop. The code is also a bit shorter and cleaner, though that is entirely my opinion, not necessarily someone elses. Online's code is even shorter and cleaner, however it is also the least user friendly, since it has no error checking whatsoever.

4. You are right: mass tokenizing should be avoided...but I never stated I use tokenize if I need to do a long loop. I use variables mostly, unless its for stupid lil aliases (like this one), where imo it doesn't matter.

5. About the offensiveness: yeah, that is a problem that will always exist in text-based communication. To me you sounded rude, but maybe u weren't that rude, just my interpretation. Same goes for this post right here, it's not intended to be offensive, just to clarify some things, so my apologies if it would sound rude.

Best to you,

FiberOPtics

Last edited by FiberOPtics; 18/05/04 02:47 PM.

Gone.
#83354 18/05/04 02:51 PM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
hehe, understood.

For anyone else who wants to see two tests in action...
Code:
alias tok {
  var %a $ticks
  tokenize 32 $str($+(a,$chr(32)),400)
  while $0 {
    tokenize 32 $2-
  }
  echo -a $calc($ticks - %a)
}
alias tok2 {
  var %a $ticks,%b 400
  while %b {
    dec %b
  }
  echo -a $calc($ticks - %a)
}


These two essentially do the same thing, whereas the first got the best score of 171ms, the second 15ms.

Anyway.. I forgot what this thread was about.. :P


You won't like it when I get angry.
#83355 18/05/04 10:46 PM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
I wouldn't recommend using multiple "msg" commands that get sent to the server. Flooding risk.

Use one to send to all the channels/nicks at one time, then take care of local echoing, so that you reduce your flooding risk. If you select to send the same thing to 10 rooms, then that's 10 commands you are sending to a server, and if you do that twice, that's 20 lines. Some networks kill you right there.

smile

#83356 18/05/04 10:49 PM
Joined: Dec 2002
Posts: 266
Z
zack Offline OP
Fjord artisan
OP Offline
Fjord artisan
Z
Joined: Dec 2002
Posts: 266
Yeah, this is what we were saying in #helpdesk the other week when we were discussing it. It just needs the same implementation as /amsg and we'll be set.


You won't like it when I get angry.
#83357 18/05/04 11:00 PM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
Code:
alias msg { !.msg $1- | var %m = $2- | tokenize 44 $1 | echo $color(own).dd -t $* %m }

That should do it all.

#83358 19/05/04 12:07 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Dear god,

no wonder your reaction...it's all making sense now. You see when you said: /msg #chan1,#chan2,etc should display your message in all these channels I losely & wrongfully assumed that you implied that it's not possible for text to be sent to multiple channels at once, much like the /amsg command.

I was surprised that it wasn't possible, so I went ahead and did /msg #chan1,#chan2 this is a test,
and noticed that in fact it didn't show anything in both channels. So then I thought: ok it seems that it's not possible to send to multiple channels at a time, so I'll simply script something fast, using a loop.

Had I known that the problem isnt that it isn't messaging, but that it's not displaying... Lol it's easy for me to understand your reaction now lol, since you did already know that it does message...then obviously my solution looked very stupid to you. It looks stupid to me as well now :tongue:

Oh well, I can safely say that today was one of the most absent minded days I've had in a long time...
I dropped my food on the way to the kitchen, my bottle of cola almost exploded when I opened it, I went to class at the wrong time, so no one was there, I couldn't find an important book that I needed, while it was just laying there in my room, I posted my first post twice not knowing it, thinking i had edited it...amazing.

Oh well, hopefully I'll get some good sleep tonight, and tomorrow is a brand new day grin

Greetz


Gone.
#83359 19/05/04 09:49 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Just a couple of details, for those who care about these things.

- you don't need the .dd property here, it's only necessary in colouring using ^K (where codes are mixed with plain text).

- you could replace
echo $color(own).dd -t
with
echo -ct own
making the code shorter (and faster, since there's one less identifier evaluation).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#83360 21/05/04 07:42 PM
Joined: Apr 2004
Posts: 73
Z
Babel fish
Offline
Babel fish
Z
Joined: Apr 2004
Posts: 73
Hey,

Maybe it could even support nicknames and =nicknames as well. laugh

-Zelda4ever
aka "The Big 'Z'"


/tokenize 32 $gettok($1-,1-,32)

Link Copied to Clipboard