mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2012
Posts: 2
B
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Jun 2012
Posts: 2
Hi, I have a problem

I'm beginner and don't know how to quickly check and retrieve data like in Arrays.

I want to store names, and some options for 27 items and f.e. in PHP the best way to do this was an Array, but here don't know how to this.
I have the possibility to predefine them or to check data online by JSON, but the problem is the data have not any id:
[{"dmgMult":1,"name":"item1","dmgReq":0},{"dmgMult":1.1,"name":"item2","dmgReq":100},{"dmgMult":1.2,"name":"item3","dmgReq":250}]

I want to find a "dmgMult" value for "name" I specify. How can I do this? I want to find the easiest (quickest) way
Thanks for answer

Joined: Feb 2011
Posts: 448
K
Pan-dimensional mouse
Offline
Pan-dimensional mouse
K
Joined: Feb 2011
Posts: 448
You are probably looking for Hash Tables.

You can take a look at the mIRC help file
"/help hash tables" (enter this in mIRC as if you type into a channel)

or here on a website.

Joined: Jun 2012
Posts: 2
B
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Jun 2012
Posts: 2
Originally Posted By: KindOne
You are probably looking for Hash Tables.

You can take a look at the mIRC help file
"/help hash tables" (enter this in mIRC as if you type into a channel)

or here on a website.


The problem is some "item names" have more than one word and I need to put more than one option to the table:
It should looks like:
DmgMult Name DmgReq
1.0=Item1=0
1.1=Item2=100
1.2=Item3=250
1.3=Item4=1000
1.4=Item5=2500
1.5=Item6=5000
1.6=Advanced Item=10000
1.65=Pro Item1=25000
1.7=Pro Item2=40000
1.75=Pro Item3=75000
1.8=Pro Item4=125000
1.85=Pro Item5=200000
1.9=God Item1=500000
1.93=God Item2=1000000
1.96=God Item3=2500000

and for example I want to know DmgMult for God Item1

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
That's not a problem. It just means you need more than one hash table, each represented by a unique item name as the key.

As far as spaces go, you can use underscores in the name and replace them when you display it to users. Or you might even want a 3rd for the "display name", so that you can use a shortname as the key.

For instance:

Code:
item_dmg_req:
item1=0
item2=100
item3=250
...

item_dmg_mult:
item1=1.0
item2=1.1
item3=1.2
....

item_displayname:
item1=Some Fancy Item Name
item2=Another Fancy Item Name
...


Alternatively, you could store this all in a single hash table by tokenizing the values together:

Code:
# mult,req,displayname
items:
item1=1.0,0,An Amazing Item
item2=1.1,100,Another Amazing Item
...


The latter might be more efficient on item lookups and take up less files on disk but you will have more scripting overhead in pulling out the specific values and updating individual fields.

If your data is read-only, or more often read than written, you'd get more bang for your buck from the 2nd setup, since pulling out specific values is only $gettok($hget(items,%itemname),N,44) (where N=1,2,3) and can be easily abstracted in an identifier. Updating individual fields can be abstracted but the process becomes less efficient (due to all the retokenization).


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard