• 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.

Unit Point Value for automatic indexing

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

So suppose I've got a few hundred unique unit types, each of which correspond to some unique object/struct in the map code.

To bind these unit types to these structs, I have been using their unit point value as the index of where the structs are in the global array.

The main function looks something like this:

JASS:
function main takes nothing returns boolean //for some event
  ...
  local unit u = GetTriggerUnit() //this is the type we want
  local integer upoi = GetUnitValue(u) //this is the unit point value
  …
  call structs[upoi].foo(…)
  …
endfunction

Would anyone have a better way of doing this?
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
After thinking about it, your way is probably more ideal. I'd just have to change my code a bit to manage it.

As things are I'm just using a python script to generate the correct assignment each time. It's like killing sparrows with a cannon but it gets the job done and hides all the internals behind the scenes, which is the high level coding experience I think vJASS should be.
 
Status
Not open for further replies.
Top