mIRC Homepage
Posted By: TristanWolf Is Nick Online - Scripting Help - 01/04/04 02:30 PM
Good morning all!

Been playing around with mIRC scripting for a couple of weeks. Having a serious problem with the following code:

Code:
#CaptureWhois on
raw 311:*:{set %WhoIsResults $1-}
#CaptureWhois end

alias UserOnline {
  if ( $$1 == $null ) {
    /return $false
    /halt
  }
  /unset %WhoIsResults
  /.enable #CaptureWhois
  /whois $$1
  /.disable #CaptureWhois
  if ( $var(%WhoIsResults,0) == 0 ) { /return $false }
  else { /return $true }
  /unset %WhoIsResults
}

alias test {
  /UserOnline Tristan
  if ( $result == $true ) { /echo Online }
  else { /echo Offline }
} 


I've tried everything I can think of, to get it to work. It keeps hanging (I think at "if ( $var(%WhoIsResults,0) == 0 ) { /return $false }") and not giving me any error msg.

Thanks a ton for any help or advice you have!
Posted By: Ponder Re: Is Nick Online - Scripting Help - 01/04/04 03:41 PM
Close..

Change the if ( $var(%WhoIsResults,0) == 0 ) bit to:
if ( !%WhoIsResults )

smile
Posted By: TristanWolf Re: Is Nick Online - Scripting Help - 02/04/04 01:08 AM
Nope.

That didn't work either.

Here's the revised code:

Code:
#CaptureWhois off
raw 311:*:{set %WhoIsResults $1-}
#CaptureWhois end

alias IsOnline {
  if ( $$1 == $null ) {
    /return $false
    /halt
  }
  /unset %WhoIsResults
  /.enable #CaptureWhois
  /whois $$1
  /.disable #CaptureWhois
  /echo Before If
  if ( !%WhoIsResults ) { /return $false  }
  /echo After If
  else { /return $true }
  /unset %WhoIsResults
}

alias test {
  /UserOnline Tristan
  if ( $result == $true ) { /echo Online }
  else { /echo Offline }
}


Try running the code. Notice how the first echo (Before If) triggers, but not the second (After If).

Any ideas?

Thanks again.
Posted By: Collective Re: Is Nick Online - Scripting Help - 02/04/04 01:14 AM
Move the code after the /whois into the raw 311 event.

The reason it doesn't work is that /whois doesn't pause scripts until it gets the server's reply. When the /whois reply does come your alias has already finished.
Posted By: TristanWolf Re: Is Nick Online - Scripting Help - 02/04/04 02:06 AM
I can't.

If the event doesn't trigger, then the if statement won't be processed.

And I believe the problem lies somewhere in the if statement itself anyway.

---

Found a minor bug in the code. Updated here:

Code:
#CaptureWhois on
raw 311:*:{ set %WhoIsResults $1- }
#CaptureWhois end

alias IsOnline {
  if ( $$1 == $null ) {
    /return $false
    /halt
  }
  /unset %WhoIsResults
  /.enable #CaptureWhois
  /whois $$1
  /.disable #CaptureWhois
  /echo Before If
  if ( !%WhoIsResults ) { /return $false  }
  /echo After If
  else { /return $true }
  /unset %WhoIsResults
}

alias test {
  /IsOnline Loki1
  if ( $result == $true ) { /echo Online }
  else { /echo Offline }
}


---

After a bit of research, I think I finally found the problem. Just not sure of the solution...

If you run the test alias, you will notice that the whois happens after the rest of the code.

I believe the /whois is not happening until after all code is being run. Is there a way to force it to wait for it to come back?

I tried creating a dummy variable, set to $true before the /whois, and set to $false in the raw. In the main code, I did a while loop to wait until the variable was $false. It never was. The code kept cycling until I broke it, and then the /whois showed.

Any ideas?

---

One last note. My objective here is to simply be able to tell if a nickname is online, even if they're not in the same room as me. If this is possible some other way, I'm open to suggestions.

Thank you so much for your help.
Posted By: Online Re: Is Nick Online - Scripting Help - 02/04/04 02:20 AM
Add the nick(s) in question to your notify list (/notify nick) and use $notify(nick).ison to tell whether they are online.
Posted By: Collective Re: Is Nick Online - Scripting Help - 02/04/04 02:45 AM
Quote:
I tried creating a dummy variable, set to $true before the /whois, and set to $false in the raw. In the main code, I did a while loop to wait until the variable was $false. It never was. The code kept cycling until I broke it, and then the /whois showed.

This is due to mIRC scripting's single-threadedness, only one piece of code will be processed at any one time. This means that even if you got the /whois reply instantly the raw event would not be processed until it had finished with your alias. I should have been clearer about this before (not that it makes much difference, since in most cases lag will mean your alias is done before you recieve the server's reply in the first place).

You can't make an alias to return whether or not a random person is online. You can draw on mIRC's notify list as Online suggested, though you can't do something like this:
Code:
alias IsOnline {
  notify $1
  return $notify($1).ison
}

It will always return $false, unless they were on your notify list before (and mIRC thinks they're online).
Posted By: TristanWolf Re: Is Nick Online - Scripting Help - 02/04/04 03:35 AM
So any suggestions at this point?
Posted By: Charlie Re: Is Nick Online - Scripting Help - 02/04/04 08:05 AM
there is no way, your code will work like you want.
here is the 'correct' one.

Code:
  #CaptureWhois on
  raw 311:*: { set %WhoIsResults $1- }
  raw 318:*: {
    if ( %WhoIsResults ) { echo -a $2 is Online }
    else { echo -a $2 is Offline }
    .disable #CaptureWhois
  }
  raw 401:*: { unset %WhoIsResults }
  #CaptureWhois end

  alias IsOnline {
    if ( $1 == $null ) { return $false }
    unset %WhoIsResults
    .enable #CaptureWhois
    whois $1
  }

  alias test { IsOnline Loki1 }


but, instead use above code with /whois command, you should try
/ison command. usage: /ison <nick> [nick] [nick] [...]

Code:
  raw 303:*: {
    if (%IsOnline) {
      if ($istok($1-,%IsOnline,32)) { echo -a %IsOnline is Online }
      else { echo -a %IsOnline is Offline }
      unset %IsOnline
    }
  }
  alias IsOnline {
    if ( $1 == $null) { return $false }
    set %IsOnline $1
    ison $1
  }
  alias { test IsOnline Loki1 }
© mIRC Discussion Forums