mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2004
Posts: 9
T
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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!

Joined: Apr 2004
Posts: 7
P
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
P
Joined: Apr 2004
Posts: 7
Close..

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

smile


-----
"No tears please, it's a waste of good suffering" --Pinhead
Joined: Apr 2004
Posts: 9
T
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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.

Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
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.

Joined: Apr 2004
Posts: 9
T
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
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.

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Add the nick(s) in question to your notify list (/notify nick) and use $notify(nick).ison to tell whether they are online.

Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
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).

Joined: Apr 2004
Posts: 9
T
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
T
Joined: Apr 2004
Posts: 9
So any suggestions at this point?

Joined: Dec 2002
Posts: 29
C
Ameglian cow
Offline
Ameglian cow
C
Joined: Dec 2002
Posts: 29
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 }


Charlie

Link Copied to Clipboard