mIRC Home    About    Download    Register    News    Help

Print Thread
#145200 19/03/06 11:10 PM
Joined: Mar 2006
Posts: 5
L
laney Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Mar 2006
Posts: 5
I am a new to Mirc scripting, but not programming. I am trying to read a webpage using sockets from within mirc and take the the html returned line by line and use regex to parse out the info i want. The script works, sort of :s It gives me a "0 Unknown command" or "1 Unknown command" error messages (tons of them) . And it is not overwriting my hash table, just appending or overwriting the individual entries. If i take the regex command out, i don't get the unknown command error message. But i get the info i want :s

alias checktop {

sockopen ladder xwis.net 80
}

on *:sockread:ladder:{
if ($sockerr > 0) {
return
}
:nextread
sockread %temp
if ($sockbr == 0) return
if (%temp == $null) {
%temp = -
}
$regex( %temp , <b>(\w+) )
set %test $regml(0)
if ( %test != %azero ) {
inc %count
set %playname $regml(1)
echo -a %playname %count
}
$regex(%temp,(\d+)\sPoints)
%test = $regml(0)
%azero = 0
if ( %test != %azero ) {
set %playpoint $regml(1)
set %addit Rank %count Points %playpoint
echo -a %addit
hadd -m top50 %playname %addit
hsave -o top50 testit.txt
}

goto nextread

}
on *:sockopen:ladder:{
sockwrite -n $sockname GET /xcl/ra2/ HTTP/1.1
sockwrite -n $sockname Host: xwis.net $+ $crlf $+ $crlf
}

on *:SOCKCLOSE:ladder: {
echo -s *** $sockname just closed
}


alias gettop {
set %playname ""
set %playpoint ""
set %azero 0
set %count 0
checktop
; hfree top50
chklist
; :error
; echo -a $error
}

alias chklist {
if (!$hget(top50,0).item) { msg $nick No data blush }
else {
%i = 1
while (%i <= $hget(top50,0).item) {
%Item = $hget(top50,%i).item
%reason = $hget(top50,%Item)
echo -a %Item - %reason
inc %i
}
}


i do a call to gettop and it loops and displays the info in the right order, then spits out a whole bunch of unknown command errors - it doesn't seem to be processing in a linear fashion either - when i am reading thru the html, it displays the output - the hash file entries are essentially correct. It displays the output from chklist first tho, then parses the html - but the command is after it :s Any help or light you can shed here would be so much appreciated laugh

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
The problem is that $regex returns a number representing the number of matches to the regex. You have the $regex command without any command before it, so mIRC tries to execute the returned value as a command.

To solve this, in mIRC 6.17 (only) you can use this code:

noop $regex(......)

in mIRC before 6.17, you can use this code:

var %r = $regex(.......)



-genius_at_work

Joined: Mar 2006
Posts: 5
L
laney Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
L
Joined: Mar 2006
Posts: 5
Well that worked like a charm laugh Thank you very much. I find lots of info on the net about mirc scripting, but not much on putting all the pieces together.

I have one more question, i call the alias in the script by typing /gettop at the command line. I am assuming that this then opens the socket by calling checktop and then reads it, then returns control to the calling program gettop. I want to overwrite/recreate the hash table every time the script is run. But I can't seem to place the /hmake /hfree in the right spot w/o getting either the table is already made error on hmake or the table doesn't exist with the hfree :s. I am guessing my error is that the program is not executing in the order i am assuming. If anyone could shed some light on it would be much appreciated again.

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
In the GETTOP alias, put this command right before the call to checktop:

if ($hget(top50)) hfree top50

If the hash table exists, it is freed, otherwise it's not freed.

You may also want to add this line to the CHECKTOP alias, right before the sockopen command:

if ($sock(ladder)) sockclose ladder

That way, if the socket is already open, it will be closed in order to prevent errors.

-genius_at_work


Link Copied to Clipboard