• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Unit Point Value for automatic indexing

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