mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2004
Posts: 509
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
1. %VariableThatDoesNotExist is null.

Code:
      echo $chan this part triggers
      if ($eval($+(%,VariableThatDoesNotExist,$nick),2) != $null) {
        blah blah
      }
      echo $chan this part triggers
      else {
        echo $chan This part does not trigger.
        }


Since it does not triger for the != $null, it should trigger for else { }, right?

Rather than using else, I've even used:

Code:
      if ($eval($+(%,VariableThatDoesNotExist,$nick),2) == $null) {
        echo $chan This does not trigger
      }


Still same.

So how do I get it to work? I put the bottom if statement on top of the top if statement.

And then it works.

In other words, this part works:

Code:
      if ($eval($+(%,VariableThatDoesNotExist,$nick),2) == $null) {
        blah blah
      }
      elseif ($eval($+(%,VariableThatDoesNotExist,$nick),2) != $null) {
        blah blah
      }


In other words, order matters (whether %null != $null or %null == $null).

2.

mIRC goes crazy when it comes to variables that does not exist.

I have.

%seenchans #list,#of,#channels

If I have.

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) {

Will only trigger for %seenchannels.

But if I have..

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) && ($istok(%VariableThatDoesNotExist,$target,44)) !ison $target) {

It will trigger for all channels.

So that's a bummer...

And then of course, the flood protection.

If I have a paste editor that will paste in N cs, then I will see my flood output at N cs.

But if I don't use a flood script and enable flood protection in Alt O, my flood slows down but I don't see it as slowing down, so that's a bummer. A mIRC script should not be better than a default mIRC feature.

-Neal.

Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
Originally Posted By: LostShadow
1. %VariableThatDoesNotExist is null.

Code:

echo $chan this part triggers
if ($eval($+(%,VariableThatDoesNotExist,$nick),2) != $null) {
blah blah
}
echo $chan this part triggers
else {
echo $chan This part does not trigger.
}



Since it does not triger for the != $null, it should trigger for else { }, right?
No, an else/elseif have to be used directly after the if statement.

Originally Posted By: LostShadow
2.

mIRC goes crazy when it comes to variables that does not exist.

I have.

%seenchans #list,#of,#channels

If I have.

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) {

Will only trigger for %seenchannels.

But if I have..

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) && ($istok(%VariableThatDoesNotExist,$target,44)) !ison $target) {

It will trigger for all channels.

Quote:
elseif (($istok(%seenchans,$target,44)) || ($target == $me)) {
This line is correct, i'm not sure why it's not working for you but :
Quote:
elseif (($istok(%seenchans,$target,44)) || ($target == $me)) && ($istok(%VariableThatDoesNotExist,$target,44)) !ison $target) {
This line is wrong in any case because $istok can only return $true or $false, so you trying to do something like //if ($true/$false !ison $target) { } and because of the &&, this will never work


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 509
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Originally Posted By: Wims
Originally Posted By: LostShadow
1. %VariableThatDoesNotExist is null.

Code:

echo $chan this part triggers
if ($eval($+(%,VariableThatDoesNotExist,$nick),2) != $null) {
blah blah
}
echo $chan this part triggers
else {
echo $chan This part does not trigger.
}



Since it does not triger for the != $null, it should trigger for else { }, right?
No, an else/elseif have to be used directly after the if statement.


So you're saying the /echo got in the way?

Quote:
Originally Posted By: LostShadow
2.

mIRC goes crazy when it comes to variables that does not exist.

I have.

%seenchans #list,#of,#channels

If I have.

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) {

Will only trigger for %seenchannels.

But if I have..

elseif (($istok(%seenchans,$target,44)) || ($target == $me)) && ($istok(%VariableThatDoesNotExist,$target,44)) !ison $target) {

It will trigger for all channels.

Quote:
elseif (($istok(%seenchans,$target,44)) || ($target == $me)) {
This line is correct, i'm not sure why it's not working for you but :


It does work for me. It only triggering for %seenchans is what I want. But when I add the &&, it triggers for non-seenchans too.

Quote:
Quote:
elseif (($istok(%seenchans,$target,44)) || ($target == $me)) && ($istok(%VariableThatDoesNotExist,$target,44)) !ison $target) {
This line is wrong in any case because $istok can only return $true or $false, so you trying to do something like //if ($true/$false !ison $target) { } and because of the &&, this will never work


Which is why removing it solves the problem. But I don't see why it has no longer follow %seenchans and work for non-seenchans too.

-Neal.

Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
Originally Posted By: LostShadow
So you're saying the /echo got in the way?
What do you mean, i don't understand :s ?
maybe this will help you :
Code:
alias syntax {
  if (1 != 1) echo -a 1
  echo -a ?1
  elseif (2 == 2) echo -a 2
  else echo -a else 1
  ;-
  if (1 != 1) echo -a 1
  elseif (2 != 2) echo -a 2
  echo -a ?2
  else echo -a else 2
}


typing /syntax only echo ?1 and ?2 because each time, the /echo *break* the if-elseif-else statement

I don't see any problem with the $istok, just use :
if ($istok($+(%seenchans,$chr(44),$me),$target,44)) {


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 509
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Okay, I'll remove the echo's.

This doesn't work.

if (% != $null) {
do this
}
elseif (% == $null) {
do this
}

1 has to work, right? But none trigger.

This does, though.

if (% == $null)
do this
}
else {
do this
}

In other words, I had to rearrange the order.

Edit: fixed.

Last edited by LostShadow; 01/12/07 12:40 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: LostShadow
So you're saying the /echo got in the way?


Yes, that's what he's saying. Unless the echo is IN the IF's {}'s, it will prevent the ELSEIF or ELSE from working.

Valid:
if (this) { do this }
elseif (this) { do that }

Invalid:
if (this) { do this }
echo -a something
elseif (this) { do that }


Note that anything placed where that echo line is will prevent the ELSEIF from working.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Originally Posted By: LostShadow
This doesn't work.

if (% != $null) {
do this
}
else (% == $null) {
do this
}

/else doesn't take a condition, so it wouldn't work, would it?

Perhaps in future it would be better to post your scripting "bugs" in the Scripts & Popups forum, or spend 30 seconds in a help channel to see if anyone can explain them.

Joined: Jan 2004
Posts: 509
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Sorry I meant else { } and elseif( ) { }. It's edited.

I manually typed it... Forgot the if in elseif.

Back to Riamus2.

Wow, weird how the /echo is like a halt or return.

I used the /echo's to debug so I know where the script stops.

That kind of sucks.

-Neal.

Last edited by LostShadow; 01/12/07 12:42 AM.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Sorry, but I don't get your point. you can debug with echos that easy, and dont have to break the if-then-else structure (?)
Code:
alias checkvar {
  ; -stuff-
  echo -a START of the if-else statement is reached

  if ($eval($+(%,VariableThatDoesNotExist,$me),2) != $null) {
    echo -a IF  triggers, the var has a value
    ; -stuff with if-
  }

  else {
    echo -a ELSE triggers, the var has no value
    ; -stuff with else-
  }

  echo -a END of the if-else statement is reached (thus no error) 
  ; -stuff that follows, be it if or else above-
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: LostShadow
Wow, weird how the /echo is like a halt or return.


No, it doesn't. It does, however, prevent ELSE/ELSEIF from doing anything. Anything else in the script will still happen... just not the ELSE/ELSEIF. If it acted like HALT/RETURN, nothing else would happen in the script.

Now, to explain...

If ELSE/ELSEIF could have various commands between it and the original IF, then mIRC would have a hard time trying to figure out which IF the ELSE/ELSEIF is supposed to be with. Sure, it could take the first IF preceding it, but that's not a great way to do things. I don't believe any language does it that way. If you break the IF/ELSEIF/ELSE format by inserting commands in the middle, then when mIRC gets to the ELSEIF/ELSE, it will have no idea what you're trying to compare and it will treat it the same as if you never had an IF statement.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2004
Posts: 509
L
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Jan 2004
Posts: 509
Okay that makes sense. I'll have to follow Horstl's way.

Thanks.

-Neal.

Joined: Jul 2006
Posts: 4,150
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,150
Instead of echoing what you want after each /if, you can just have one /echo before the first /if with all information you need, and in this way you'll know which statement have been executed :
Code:
echo -a > %a /// %b /// $hget(%a,%b) /// %c
if ($gettok($hget(%a,%b),-3,32)) { }
elseif (%a isin %b) && (%c isnum 8000-9000) { }
elseif ($istok(Ga.is.Ga,$hget(%a,%b),46)) { }
else { }


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Debugging tutorial: http://kthx.net/ftb


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard