mIRC Home    About    Download    Register    News    Help

Print Thread
#198900 06/05/08 11:46 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I have this:

Code:
if ...
elseif ...
elseif ...
...
else ...


Each if/else has a $eval check except the last one. Can/Should I put an $eval check in the last 'else' just in case something 'jumps' and the last 'else' get acidently executed?


I registered; you should too.
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

You would have to provide the code before anyone could give any advice on it.

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I'm still writing it, though I'm thinking about emailing it to a couple of you for your input and corrections on my coding.

Again I thank all of you that have helped me.


I registered; you should too.
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Why not just paste it here so we can get an idea of what it is that you're trying to do?

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
IF so fourth and so on equals to whatever (if theres a match here then the script halts, next in line checks if theres ElseIF statement)

ElseIF so fourth and so on equals to whatever (if theres a match here the script halts, next in line checks if theres another elseif statement if not jumps to else)

Else (if theres no match from the IF or ElseIF statement then whatever execution you have in your else statement will execute)

You can always not add an ELSE statement its not neccasary unless your script needs to perform something in the end if no matches were found.

Code:
alias ifs {
  if ($$1 == 1) { echo -a IF statement stops numeric match: 1 }
  elseif ($$1 == 2) { echo -a ElseIF statement stops numeric match: 2 }
  elseif ($$1 == 3) { echo -a ElseIf statement stops numeric match: 3 }
  else { echo -a The numerical value has no match }
}


Type /ifs to execute the command and type a numerical value after such has 1 up to 3

1 if the IF statement, 2 is an elseif statement, 3 is an elseif statement, any other number is the else statement has you see it never jumps to else unless theres no matches in the if/elseif statements


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Awestun I saw the post you posted after what I wrote before you deleted it...

If it doesn't "halt" within the script it's because A) your elseif structure is perhaps incorrect.

You shouldn't need the use of "halt" if properly structured sometimes it can be a such stupid thing has not properly opening and closing brackets { }

How about you post me the line in question that doesn't halt?

P.S. are you using a LOOP the old fashion method by any chance?


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I took it out and put it back the way it was originally. Then I put some echo's in there so I can watch things. I'm starting to think it's got something to do with the responce lag of a /trace on the private server. If things lag to much then I get weird responces.


I registered; you should too.
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
What kind of connection are you on and what kind of connection is the server on?

ex:. dialup, cable, dsl, t1, t3, oc1, oc3


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
FIOS


I registered; you should too.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
What it comes down to is what you have it set up as. You really have to give more that just if/elseif/else if you want help. You do not ever need a halt in an if/elseif/else to prevent it from doing the remainder of that group of comparisons. It will stop automatically whenever one of the comparisons matches and then it will jump to the line(s) following that group of comparisons.

Keep in mind that you *CANNOT* have anything mixed inbetween those comparisons...

WRONG:
Code:
if () { }
elseif () { }
msg $chan something
elseif () { }
echo -a testing
else { }


RIGHT:
Code:
if () { }
elseif () { }
elseif () { }
else { }
msg $chan something
echo -a testing


If you want something done with one of the comparisons, include it within the {}'s for that comparison.

Also, you should not use HALT at all to stop your script from continuing to execute. Use RETURN instead. HALT should be used similarly to HALTDEF to prevent builtin things from happening. For example, using HALT in an on INPUT to change how it displays/sends the text without having the text appear/send twice.


Invision Support
#Invision on irc.irchighway.net
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
The problem I'm having is that once in a while (1 out of about 20 times) when a user says something on the room the following 'ifelse' doesn't automatically halt and runs the following 'else':

Code:
on *:TEXT:*:#:{
  set $+(%,iptext) $true
  set %chan $chan
  set %nick $nick
  trace $nick
}


Code:
;trace
raw 205:*: {
...
  ;On Channel TEXT Trace User and Add If Not In File
  elseif $eval($+(%,iptext),2) {
    echo 4 -s start iptext: %iptext chan: $channumname(%chan) nick: %nick
    if ($read(iptracker.txt,w,$4 $+ *) == $null) {
      echo 7 -s [ $+ $channumname(%chan) TEXT TRACE]: added: $4
      echo 4 -s -
      write iptracker.txt $4
    }
    set $+(%,iptext) $false
    echo 4 -s end iptext: %iptext
  }  

  ;Popup/Join-user-chan Trace and Search for Name/IP Matches; Add If Not Found in File
  else {
    if ((($eval($+(%,snames),2) || $eval($+(%,ipjoinuser),2)) || $eval($+(%,ipjoinchan),2))) {
      ...
}


The only way I can stop it is to change the 'else' $eval line to:

Code:

if (((($eval($+(%,snames),2) || $eval($+(%,ipjoinuser),2)) || $eval($+(%,ipjoinchan),2))) && $eval($+(%,iptext),2)){



I registered; you should too.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
There's no need to use a dynamic variable for %iptext in your code, and by not using a dynamic variable, there's no need to double evaluate it. You echo %iptext if there's something in it, but the code, from what I can see, will just have %iptext contain $true, which is a non-text entry. Additionally you use $channumname, which isn't a mIRC identifier, so I can't tell if that might be where your problem is.

The 2nd part of the code that you provided doesn't really give us enough to make a proper evaluation as to what might be going wrong, and why.

IMO no more assistance can be rendered without the rest of that section of code.

Code:
on *:TEXT:*:#:{
  set %iptext $true
  set %chan $chan
  set %nick $nick
  trace $nick
}

Code:
;On Channel TEXT Trace User and Add If Not In File
...
  elseif %iptext {
    echo 4 -s start iptext: %iptext chan: $channumname(%chan) nick: %nick
    if ($read(iptracker.txt,w,$4 $+ *) == $null) {
      echo 7 -s [ $+ $channumname(%chan) TEXT TRACE]: added: $4
      echo 4 -s -
      write iptracker.txt $4
    }
    set %iptext $false
    echo 4 -s end iptext: %iptext
  }  

  ;Popup/Join-user-chan Trace and Search for Name/IP Matches; Add If Not Found in File
  else {
    ...


What I said about %iptext in regards to the usage of dynamic variables, also applies to the variables in
Code:
if (((($eval($+(%,snames),2) || $eval($+(%,ipjoinuser),2)) || $eval($+(%,ipjoinchan),2))) && $eval($+(%,iptext),2)){

Code:
if (%snames || %ipjoinuser || %ipjoinchan) && %iptext {

Last edited by RusselB; 07/05/08 09:07 AM.
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
$channumname is just an alias that takes a channel name #999=1 and translates it into Apple and returns %chan as Apple.

I'll change the 'else' if to:

Code:
if (%snames || %ipjoinuser || %ipjoinchan) {


The 'else' if should never execute if the previous 'elseif' did.


I registered; you should too.
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
I'm trying to write a $botcheck alias:

Code:
alias botcheck {
  if ((%host1 == 1.2.3.4) || (%host1 == 5.6.7.8)) {
    echo 4 -s [SPAMBOT ALERT]: %nick %host1
    ;msg %chan [SPAMBOT ALERT]: %nick
    echo 4 -s -
  }
  return
}


%host1 is the IP address that gets passed with %nick to $botcheck by calling the alias with:

Quote:

$botcheck(%nick,%host1)



Is there a more simple and easier way to do the %host1 checking? What if I have 5 known bot IP's I want to compare to %host1?


I registered; you should too.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As I stated, you cannot have anything mixed inbetween your if/elseif/else lines. That includes comments. If you have anything mixed in there, it breaks the format and the else will always execute and any elseif's will execute if they match even if a match was found in a previous elseif or if in that group.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
In my experience you can have as many comments and as much whitespace as you like without affecting the format. And if the format does get broken then the else will never execute.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Is this part of the same question or is this something else? Seems like we keep jumping around with different peices of code here.

Anyway, if you want to match something against several values then there are a couple of ways you can do it.

If there's just a few and they're all hardcoded then you can use $istok
Code:
if ($istok(1.2.3.4  5.6.7.8  9.10.11.12  13.14.15.16, %host1, 32)) {
  ...
}


If there are too many for that or if you want to be able to easily alter the list without having to manually edit the script you can use hash tables.
Code:
if ($hfind(hosts_list, %host1, 1)) {
  ...
}


; Use this to add a host
hadd hosts_list <YOUR-HOST-HERE>

;Use this to remove a host
hdel hosts_list <YOUR-HOST-HERE>


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: starbucks_mafia
In my experience you can have as many comments and as much whitespace as you like without affecting the format. And if the format does get broken then the else will never execute.


You're right. I had tested it prior to posting and it seemed to do what I said. However, I was getting lag at the time and it apparently changed the test output order because I tested it again and it worked with the comment in there.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard