• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

What's the best way to know an array index?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
If i have 100 items in an array (Item[1, 2, 3, 4]) and I want to detect the index of the picked item, what should I do?

The "brute-force" way I can think of is looping From 0 to 100, but, isn't there a best way?
 
You can work with Custom Values of items...
Whenever you set an item to your array, immeadetly add to that item's custom value the index. So everything will be straightforward then.
 
Well.. I already know the loop way, and Item Level, and ItemLevel and all the OE common item Values. Having an Item Indexing System requires more work.

There must be some way to directly detec the index of an item on an array =/
 
It is not much of an issue to loop through 100 values. Actually, it is very light on the CPU, as it is only comparing values. If that is the handiest way for you, then go with it, it won't cause problems in an item system. This poses a problem in systems that require rapid movement and 0.01 refresh rates. Item systems do not suffer from such things, remember when item systems used gamecache and were still pretty fast?
 
@Spartipilo: Well, think of it this way. Hashtables are O(1), looping is worst-case scenario O(n). I'm pretty sure hashtables will pass the loop in speed by a bit in a good amount of scenarios (although it is negligible). Hashtables aren't that slow, they just are considered slow when being compared to arrays, but that is a bit unfair for obvious reasons. Compared to standard functions, they are pretty good.

The best method would be SetItemUserData() though. Just assign it on the looping, it does not have to be a fully fledged indexing system unless the items are constantly being swapped around as far as indices go in the array.
 
remember that the item array index has to be bound to the item or it will be lost i used the item life for an array index once worked fine and now with textmacro you can quickly make 100 items, all with 1 more hp than the previous .

now i feel screwed -.- i already told to use the HP of the items as dummy array as first answer....and now after 20 other answer mine is told again Oo
 
now i feel screwed -.- i already told to use the HP of the items as dummy array as first answer....and now after 20 other answer mine is told again Oo

yes i was just clarifying your answer because i think its best to use item life as an array index.

Because the hp of items cannot change ingame.[/irony]

irony? :goblin_yeah::goblin_sleep:

there is a setitemlifebj
 
Status
Not open for further replies.
Back
Top