mIRC Home    About    Download    Register    News    Help

Print Thread
#10129 07/02/03 05:16 PM
Joined: Jan 2003
Posts: 119
A
AKO Offline OP
Vogon poet
OP Offline
Vogon poet
A
Joined: Jan 2003
Posts: 119
Hey, I'm currently working on a script and i'm having an issue with an if and else statement.

if ($dinfo(%data.data).action == version) {
sockwrite -n $sockname 1.0.02-07-2003
echo @server_debug $dtime $sock($sockname).ip requested version information
}
if (($dinfo(%data.data).action == voice) && ($numtok(%data.data,32) == 3)) {
if (($me isop $dinfo(%data.data).chan) && ($dinfo(%data.data).nick ison $dinfo(%data.data).chan) && ($dinfo(%data.data).nick isreg $dinfo(%data.data).chan)) {
mode $dinfo(%data.data).chan +v $dinfo(%data.data).nick
sockwrite -n $sockname Success
echo @server_debug $dtime $sock($sockname).ip successfully voiced a user
}
else {
sockwrite -n $sockname VOICE_ERROR
echo @server_debug $dtime $sock($sockname).ip unsuccessfully attempted to voice a user
}
}
else {
sockwrite -n $sockname VOICE_SYNTAX_ERROR
echo @server_debug $dtime $sock($sockname).ip did not specify a correct syntax to voice
}


Currently, the 1st if statement is triggering the 2nd if statement...I know there are ways around it, but I'm just wondering if anyone else has noticed this....

What I know I can do is seperate the 2nd if statement out to another section, and only check for the %data.data = voice, and have it look at the syntax afterwards......

but Im just wondering if anyone else has encountered this issue and maybe has brought it up? It would be nice to have the ability to seperate if and else statements like that..

{
if { }
{
if { }
else { }
}
else { }
}


Alternatively I could use a halt or return but it just doesn't look right to me to do it that way smile I think I solved my own problem though, LOL....

#10130 07/02/03 05:25 PM
Joined: Jan 2003
Posts: 119
A
AKO Offline OP
Vogon poet
OP Offline
Vogon poet
A
Joined: Jan 2003
Posts: 119
I fixed it, by seperating the action and the syntax of the 2nd if statement.

I now first check the action and then check for syntax in an if statement beneath that....but I dunno, was just hoping I could've done it the other way..heh..

#10131 18/02/03 08:44 AM
Joined: Feb 2003
Posts: 12
A
ash Offline
Pikka bird
Offline
Pikka bird
A
Joined: Feb 2003
Posts: 12
I think what you're looking for is elseif.

Code:
 
  if () {
  }
  elseif () {
  }
  elseif () {
  }
  elseif () {
  }
  else {
  }
  say hi


If the first if is true, that will be the only block that is executed (it will go strait down to the 'say hi' line). If the first if is false, it will check the elseif. If the elseif is true, it will execute the block and go down to the say hi. If all of the elseifs fail it will execute the else block.

elseif is just short hand for doing:
Code:
  if () {
  }
  else if () {
  }
  else if () {
  }
  else () {
  }


Link Copied to Clipboard