mIRC Home    About    Download    Register    News    Help

Print Thread
#152587 03/07/06 01:22 AM
Joined: Aug 2003
Posts: 20
S
SGR Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2003
Posts: 20
Code:
alias checksteam {
  if ($regex($1-,/^STEAM_[01]:[01]:\d{2,10}$/) > 0) {
    return $true
  }
  return $false
}


Any reason why this always returns $false? Even if a string matching the Regex is provided as the argument? Indeed, how can I get this to perform "as expected" for the regex:
Code:
/^STEAM_[01]:[01]:\d{3,11}$/

I've tried using "$+ $chr(x) $+" in place of [, : and ] -- didn't get me anywhere.

Thanks in advance,

Alex.

#152588 03/07/06 01:33 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I don't know much about regex, but I did note that your code will always return $false, even if it also returns $true

The correct format (to keep both from happening) would be
Code:
alias checksteam {
  if ($regex($1-,/^STEAM_[01]:[01]:\d{2,10}$/) > 0) {
    return $true
  }
  else {
    return $false
  }
} 


I don't know if that solves the problem (ie: there were times when you were getting both $true and $false returned) or if there is a problem with the regex, which always caused just the $false to be returned.

#152589 03/07/06 01:37 AM
Joined: Aug 2003
Posts: 20
S
SGR Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2003
Posts: 20
Funnily enough, I did actually have it using the method you described, I removed it from my post as it appeard to be redundant code. Still, I'll keep that behaviour in mind for the future.

Regardless, even using a full if{}else{} block; the same behaviour is still observed ($false is always returned)

Last edited by SGR; 03/07/06 01:39 AM.
#152590 03/07/06 01:40 AM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
There's a problem with using {2,10} in the same line since it has a comma. You need to put the pattern into a variable and use that instead.

Code:
alias checksteam {
  var %r = /^STEAM_[0-1]:[0-1]:\d{2,10}$/
  return $regex($1-,%r)
}


Returns 1 if valid and 0 if not. There's certainly no need to use an if-else here.

if (1) and if ($true) are essentially the same, as are if (0) and if ($false).

So, using this in another script:

if ($checksteam(id)) will be false if it returns 0 and true if it returns 1.

#152591 03/07/06 02:11 AM
Joined: Aug 2003
Posts: 20
S
SGR Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2003
Posts: 20
Strange, I thourght I'd replied to this already. NEvermind.

Anyway, thanks schaefer31, yes the , was the problem - thanks.

I'm surprised mIRC doesn't stop parsing for paramters when it encounters the / and not start again until the ending / of the regex but heh.

Quirks there will always be.

#152592 03/07/06 11:33 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Quote:
[...] your code will always return $false, even if it also returns $true


This is impossible, a routine can never return twice. When the first /return is encountered, execution stops. His usage of /return's is absolutely correct and in fact saves a few characters (and CPU cycles) by avoiding /else.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard