• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Unit Point Value for automatic indexing

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,342
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,342
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