mIRC Home    About    Download    Register    News    Help

Print Thread
#179696 26/06/07 09:39 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I rewrote it, now everything working, but it must be a cleaner way to write it? would be nice if someone could explain or show me? smile
Code:
on *:ban:#: {
  if ($me isop $chan) && ($banmask iswm $address($me,5)) && ($banmask != *!*@*) && ($banmask != *!~*@*) && (%ban.pro == Enabled) {
    mode $chan -bo $banmask $nick
    .notice $nick Don't ban me!!
  }
  if ($me !isop $chan) && ($banmask iswm $address($me,5)) && (%ban.pro == Enabled) {
    echo -a Not oped in $chan $+ , can't unban my self.
  }
  else {
    if ($me isop $chan) && ($banmask != *!*@*) && ($banmask != *!~*@*) && (%kickonban == Enabled) {
      var %banmask = $banmask
      if ($ial(%banmask,0).nick == 0) { return }
      if ($banmask iswm $address($me,5)) { return }
      var %totbu = $ial(%banmask,0).nick
      var %stb = 1
      while (%stb <= %totbu) {
        echo -a working -> $ial(%banmask,%stb).nick
        if (%stb == %totbu) { halt }
        inc %stb 
      }
    }
  }
}

Last edited by sparta; 26/06/07 11:11 PM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #179713 27/06/07 05:16 AM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Just a few comments on the code in general.

1) Why do you put '$banmask' into '%banmask' ? You aren't changing it anywhere, so this is pointless. Just use '$banmask'.

2) As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'.

3) The if's look to be checking the same things a few times, so can be re-structured to not re-check so many times.

4) Unless you've got code after this, why are you doing an extra 'if' within the while? It's superflouous.

Bekar #179719 27/06/07 09:23 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I fixed 1 and 2, dunno how to fix the last 2.

3) The if's look to be checking the same things a few times, so can be re-structured to not re-check so many times.

4) Unless you've got code after this, why are you doing an extra 'if' within the while? It's superflouous.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
sparta #179721 27/06/07 09:33 AM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Code:
else {
  if {

equals: elseif {

Code:
while (%stb <= %totbu) {
  echo -a working -> $ial(%banmask,%stb).nick
  if (%stb == %totbu) { halt }
  inc %stb
}

Why use "if (%stb == %totbu) { halt }" at all? The while statement will automatically stop when %stb equals %totbu since that *is* your while statement.

5618 #179727 27/06/07 11:19 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: 5618
Why use "if (%stb == %totbu) { halt }" at all? The while statement will automatically stop when %stb equals %totbu since that *is* your while statement.


As mentioned, what you have there is unnecessary as your WHILE statement will automatically complete when those are equal. Beyond that, if you *did* want to halt the full script, you'd want to use RETURN instead of HALT, like you did previously. Or, if you just want to stop the WHILE loop, but want the script to continue running, then use BREAK.


Invision Support
#Invision on irc.irchighway.net
Bekar #179730 27/06/07 12:18 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
Originally Posted By: Bekar
2) As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'.

eh? That don't work.

RoCk #179731 27/06/07 12:30 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Quote:
2)As this is a channel-based event, you can drop the '$chan' in the if tests, i.e. 'if ($me isop)'.

it could have been working, on @*:ban:, then i could remove that line, but since i also use if ($me !isop $chan) { do stuff } it dosent work that well in my code wink


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
RoCk #179734 27/06/07 12:51 PM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
You're right.. Why did I think that worked ?!

Anybody know if using '#' is faster than '$chan' in a channel-based event?

Code:
if ($me isop #) {

Bekar #179736 27/06/07 01:09 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
I don't know if it's faster or not but I normally use # over $chan in those types of situations, just a habit I guess. It's 4 less characters though smile

Bekar #179756 27/06/07 07:28 PM
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
i make some test and it show that # is a little bit faster than $chan ( 10 ms with 5000 iteration ) but not tested with an event


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #179760 27/06/07 08:03 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
Maybe it's a little faster because with # there's no chance for parameters and properties so no need to check? I'm not sure if that's true or not, but it looks good. Could be true. confused

Bekar #179769 27/06/07 11:28 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I kind of have to laugh about such questions regarding speed. Yes, speed is important... to a point. Unless you have a huge script that does a LOT all at once, even a couple hundred miliseconds isn't going to be noticeable. It's just my opinion that worrying over that little bit of speed change is not worth the effort, of course. Now, if we're talking about seconds of difference, then it's worth caring about.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #179772 27/06/07 11:57 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
One identifier may not make a noticeable difference, but add that one unnoticeable difference together with all the other unnoticeable differences and suddenly you have a noticeable difference. But you're right, 10ms is nothing to worry about.

RoCk #179775 28/06/07 12:22 AM
Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Yeah, I agree.

Was just curious..

RoCk #179777 28/06/07 12:49 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: RoCk
One identifier may not make a noticeable difference, but add that one unnoticeable difference together with all the other unnoticeable differences and suddenly you have a noticeable difference. But you're right, 10ms is nothing to worry about.


Only if it's all done at once. And in most cases, that is not true. There was discussion over how not using {}'s could make it "noticeably" faster. I have a LOT of scripts running and many of them use TEXT events in channels with a lot of text. The majority of code in my scripts use {}'s and there isn't enough of a slowdown to even notice without trying to detect it with a script. Everything happens fast enough that it might as well be called "instant." Sure, if you went through and ran all of my scripts without those {}'s and tested it with a script, you'd find that not using them would be faster... but when actually using the scripts as they are currently written, there isn't anywhere near enough slowdown to notice.

It would really take a lot of things happening all at once for it to really be noticeable, or else some loop that needs to loop a LOT of times before getting a result, or something similar. That's all I'm saying. I believe in optimizing code, but there are just some things that really aren't worth bothering with and {}'s or ()'s or #/$chan are some of them. As such, I would use:

Code:
if (this == that) { do this in $chan }


Rather than:

Code:
if (this == that) do this in #


Or:

Code:
if this == that { do this in # }


Or whatever. Again, it's just my opinion. Besides, I personally find the first one much easier to read quickly without having to think about it. That makes for easier debugging.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard