mIRC Home    About    Download    Register    News    Help

Print Thread
#80539 25/04/04 06:51 AM
Joined: Jan 2004
Posts: 15
J
jONEz Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jan 2004
Posts: 15
Is there anyway to create a multidimensional array in IRC? Basically what I'm trying to do is create a dynamic list of hash tables or tokens that i can iterate through easily (preferably by an integer index). I tried doing some searches but haven't had much luck, if you can help please reply, thanks!

Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
mIRC does not support arrays, it can do hash tables though. Somewhere else here I noticed a post that mentioned being able to script an array though I've never bothered to try. I am sure it [a scripted array] wouldn't be terribly fast though.

Joined: Jan 2004
Posts: 15
J
jONEz Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jan 2004
Posts: 15
I think I've figured out what I need to do, but I have a question on the topic as I've only used tokens in a few situation. Can tokens contain tokens as long as they have different deliminators? Is this a bad idea? I think I could just splice the data up based on two unique characters I choose.

Joined: Dec 2002
Posts: 2,985
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
Not sure of the answer to that but my wild guess is no as I haven't tried it. Someone else may be able to confirm either way.

Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
Tokens could work, but variable lenght limit isn't much. I'd go for hashtable.


Code:
//if ( khaled isgod ) echo yes | else echo no
Joined: Jan 2004
Posts: 15
J
jONEz Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jan 2004
Posts: 15
I think I may have been a bit unclear as to what I'm trying to accomplish, here's an example to help illustrate the situation a little better. Say were writing a script to maintain a list of people going to a party.

For each person we need to know;
Their name, age, partners name, and what they're bringing to the party. This list changes all the time, and were not sure how many people are coming.

So we have two things; the first is a list of people coming, the second is a list of their information. I need to be able to cycle through the list of people by an integer index, and pull the users data from their entry as well.

So yes, I could use Hash Tables for the users information, but how would I compile this set of Hash Tables into a dynamic list? To use this method I would need to create / delete Hash Tables on the fly, and be able to access any of their personal information by using the number they assigned upon registration (eg the index they are in the list of people coming). How would I go about implementing something like the above?

Is there a limit on tokens as to how large they can be? using two unique deliminators I could also accomplish the above I believe. What do you think is the best method to accomplish the situation above? Thanks again for the help guys!

Last edited by jONEz; 25/04/04 02:36 PM.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Why not just create a hash table and have each item use tokens like this:
joe smith38jane smithspoons

Then you can use $gettok($hget([color:purple]myhashtable, item-number).data, token-number, 1)[/color] to refer to peices of data. Using hash table indexes like that isn't vey efficient, but it's probably still fast enough.

The maximum length for any string in mIRC is approx. 940 characters, minus command names you get a practical length for variables or parameters of around 920 characters.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

you can use a hash table + tokens for that.

For example: John.Doe=32~lynn~coffee machine~male~ etc.

You use John.Doe instead of John Doe, because you cannot use items which contain spaces in a hash table.

(Well you could actually load items in a hash table from a pre-written file, containing spaces, but performing any operation on the data or the item itsself, would cause the space to be gone.)

As you can see the data that comes with an item is linked with the token ~ which is $chr(126).

To retrieve information from this hash table (let's call it party), check the help file for /help hash tables and /help token identifiers and /help tokenize

$hget(party,0).item <-- number of people that are coming to party

$hget(party,x).item <-- gives the item (people's name) of the x'th item in the hash table

$hget(party,x).data <-- gives the data (people's information) of the x'th item in the hash table

$hget(party,john.doe) <-- gives the data that comes with the specified item

/hadd party jane.doe 21~dan marino~mixer~female~... <-- add an item with their personal information

/hdel party john.doe <-- delete a person who decided not to come

etc. etc.

Now to catch specific values from the data, you can use tokens.

tokenize 126 $hget(party,john.doe) <-- $1 = age, $2 = partner's name, $3 = gift, $4 = sexe, ....

or $gettok($hget(party,john.doe),x,126)

etc. etc.

I hope this was somewhat helpful for you.

Greetz


Gone.
Joined: Jan 2004
Posts: 15
J
jONEz Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jan 2004
Posts: 15
Thanks for the help guys! I got it working, I only have one other question for you, what is the correct syntax to create an empty token? Or is it ok for me to create a variable with the $addtok command? eg; set %mMatch $addtok(%mLeague,%mMatch,37)

Thanks again!

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Yeah, you can simply set a variable with addtok like this e.g.:

%x = $addtok(%x,%y,37)

This will add the token %y to the variable %x (if %x didnt exist yet, then mIRC will create it first and then set it)

or u can use of course set %x $addtok(%x,%y,37) though if this variable %x changes often i don't use set %x .. cuz it keeps setting that variable, while it's already set. But that's really mice droppings we're talking bout here :tongue:

Greetz


Gone.
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
$addtok may or may not be what is needed. Remember, with $addtok, it only adds the new token if it doesn't already exist in the string (in this case, your %x).

If 32 is the first token as the person's age, and another numeric data item to be added later is also 32, $addtok won't add it since it already exists. For example, Age = 32 and MaxBeersDrunkInOneSitting = 32 ... the second token value of "32" will not be appended as you might expect it to be. So, if you just want to add something to the end (without checking to see if it already exists first), just append it.

%x = $+(%x,•,new stuff goes here)

Also, none of the token identifiers allow for "blank" tokens. So, to represent an empty token, use a specific token to represent an empty token, perhaps using a string, like ~empty~ or a single $chr(255) (which is a ÿ) or whatever you want, anything that cannot be a valid data value.

%x = $+(%x,•,~empty~)
%x = $+(%x,•,ÿ)


NOTE: is Alt+0149 and is not used much in actual values. This makes it a wonderful token separator, used as $gettok(%x,2,149).


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

never noticed there was a reply to my post.

You are correct, simply appending to %x is better in this case, for the reasons that you stated.


Greetz


Gone.

Link Copied to Clipboard