mIRC Home    About    Download    Register    News    Help

Print Thread
#77298 31/03/04 03:54 AM
Joined: Mar 2004
Posts: 111
Z
Zeusbwr Offline OP
Vogon poet
OP Offline
Vogon poet
Z
Joined: Mar 2004
Posts: 111
Ok, can someone plz post some examples of binvars in use? something like writing a binvar to a hash table, a ini file, and a variable. then accessing them, like a $read or $hget command for binvars. Ty smile

Note: i need it to be hash tables or ini files and junk cuz it cant be Temp. TY smile

#77299 31/03/04 11:55 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
First off, set a binary variable:
/bset -t &moo 1 im the content
&moo is the name of the binary variable.
1 is the byte offset at which the content should be added, since it's an empty variable we'll start from the first byte.
The -t switch tells mIRC that you're specifying plain text, if you don't use that switch the content must be input as space-delimited ASCII codes. So the non-text equivalent would be:
/bset &moo 1 105 109 32 116 104 101 32 99 111 110 116 101 110 116
and you'd have the exact same binary variable.

To add a binvar to a hash table is simple, /hadd has a -b switch specifically for this:
/hadd -b hashtable binaryitem &moo
To set a binvar to the value of a hash item you simply use $hget() like so:
var %bytes = $hget(hashtable, binaryitem, &moo)
The $hget() puts binaryitem from the hash table hashtable into binvar &moo.
The var %bytes = is nothing to do with the actual binvar assignment, it's simply there because the $hget() returns the number of bytes that were written to the binvar (or in other words, the new length of the binvar), and you can't have the identifier alone on a line since mIRC will always interpret the first word on a line in a script to be a command. So to prevent that from happening we simply assign the returned value to a variable, sometimes it's useful information to have stored, but mostly it's just there for syntax purposes.

To save and load a hash table which contains binary data you simply need to use the -b switches for each. Since there's nothing special about the commands when you use the -b switch I won't go into detail on how to use them.

Unfortunately you can't save binary variables to INI files directly. An INI file is a plain-text format, and as far as I'm aware INI files have no way to support binary data. However, if you know the binary variable contains only plain text, you can retrieve the text from it using $bvar() (in chunks if necessary) and assign the contents to an ini file just as you would with any normal text data.
eg.
Code:
writeinibin {
  ; Usage: /writeinibin <inifile> <section> <&binvar>
  if ($0 < 3) return
  var %i = 1, %j = 1
  while ($bvar($3, %j, 900).text != $null) {
    writeini -n $1 $2 $+(binary, %i) $ifmatch
    inc %i
    inc %j 900
  }
}

readinibin {
  ; Usage: /readinibin <inifile> <section> <&binvar>
  if ($0 < 3) return
  var %i = 1, %j = 1
  while ($readini($1, n, $2, $+(binary, %i)) != $null) {
    bset -t $3 %j $ifmatch
    inc %i
    inc %j $len($ifmatch)
  }
}

You could then use /writeinibin inifile section &binvar to write to INI files (only by section, you can't specify an item) and /readinibin inifile section &binvar to retrieve the values. However, the content is still subject to the usual stripping rules of INI files (control codes stripped). It's not ideal but that's because INI files really aren't a good medium for binary-type data.

Hopefully you'll find some of this useful and not too confusing...


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#77300 01/04/04 03:47 AM
Joined: Mar 2004
Posts: 111
Z
Zeusbwr Offline OP
Vogon poet
OP Offline
Vogon poet
Z
Joined: Mar 2004
Posts: 111
VERY useful!! smile!@!@!@! grin

I was just confused cuz the helpfile didnt explain much to me more than the useage of the commands and i didnt even get the point lol. And i was told to go to mircscripts.org but the site was down!!! lol. But anyway, thanks a ton! smile

#77301 01/04/04 06:09 AM
Joined: Jan 2003
Posts: 428
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Jan 2003
Posts: 428
A great, clear, intelligible post - thanks! laugh

PM


IRCnet & DALnet @#travelersinn
:-: IRC for fun and relaxation :-:
#77302 04/04/04 06:14 AM
Joined: Jan 2004
Posts: 18
N
Pikka bird
Offline
Pikka bird
N
Joined: Jan 2004
Posts: 18
Ok, I came across this thread as it is one of the few tutorials on the web I could find on binvars. I need to turn to binvars as I came across the hard limit of normal variables - at 920-odd characters.

So reading this thread I wrote some code to convert my old %variable being assigned from a hash table, to it being assigned to a binvar, but I get this:

* String too long: $bvar (line 211, Channel Tracker.mrc)

I thought they were supposed to be only limited by memory?

Line 210 - 211 is this:

/var %bytes = $hget(%hashtable,AllChannels,&AllChannels)
while (%countit <= $numtok($bvar(&AllChannels,1,$bvar(&AllChannels,0)),44)) {

That should return about 920 characters of comma seperated channel names. Help appreciated on where the problem is.

Last edited by Nutter; 04/04/04 06:15 AM.

Nutter
GameSurge IRC Network
www.gamesurge.net

Link Copied to Clipboard