Quote:
Originally Posted by DustyPorViva
Zero: Yours confuses me  I'll have to go over it after I go to bed.
|
Basically, the has function just takes the text (be it a gui name or so) and returns some sort of number. A very SIMPLE example of a hash function might be:
PHP Code:
function hash(i) return i%10;
Of course, that is designed for integers, not strings. It's a programming technique designed mostly for creating hash tables that are used in sorting and such but I think it would work pretty well in this situation.
EDIT: Here's a simpler alternative if you don't want to deal with hashing:
In the onCreated of a "Main"-like system wnpc, put:
PHP Code:
global = new TStaticVar("_");
global.join("globalfunctions");
Then in the globalfunctions class:
PHP Code:
//#CLIENTSIDE
function onCreated() {
this.showimgtable = {
"hearts",
"fullhearts",
"arrows"
};
}
function getImgIndex(text) return 201 + this.showimgtable.index(text); // If index is -1, then it will return 200
function getImg(text, obj) with (obj) return findimg(getImgIndex(text));
Now it's easy to showimgs:
PHP Code:
showimg(_.getImgIndex("hearts"), "heart.png", 204, 405);
_.getImg("fullhearts", this).image = "fullhearts";
Make sense?