| 07-07-2004, 07:54 PM | #1 |
Does anyone know of a function that takes a variable that holds a specific item within an array and returns its index within that array? EX: i need to say set udg_Index = INDEXFUNCTION(GetClickedDialogBJ()) the part i don't know is what INDEXFUNCTION's name really is... if there IS a function like that... :( |
| 07-07-2004, 09:24 PM | #2 |
hmmmm.... dont know if the return bug also works with dialog stuff, but if it does you could use that to get integers from the dialog stuff and use those for the arrays indexs the when you need to get stuff from the array just do set udg_Index = dialog_to_int_function( GetClickedDialogBJ() ) to find the index based on that dialog elements handle. |
| 07-07-2004, 10:21 PM | #3 |
There is no such function. The only way to do that if you have a mere array is to loop through all entries of the array and compare them with the searched index. Of course that is very inefficient for large arrays. Using the return bug value as index of the array does not work (at least not easily though there is a way) because the value gets far too large for an array index. Now computer science found many ways to make storage and retrieval of information more efficient. A way is to sort that array which allows to apply binary search, which is a lot more efficient. A more easy way in JASS is to use the gamecache, which is the native implementation of a hashtable. That allows to retrieve and store info in pretty much constant time (as long as several conditions are met). The gamecache allows you to store information under a specific string and since usage of the return bug allows you to convert anything to an integer and that can be converted to a string with I2S (direct conversion from handle to string is not recommended), you can store info under anything, be it unit, destructable or whatever. |
| 07-12-2004, 02:22 PM | #4 |
I wonder if someone already made an implementation using binary searching. Has anyone created such a function yet? |
