• 🏆 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!

how to print out names of units, items, etc?

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

How would one print out the names of units/handles that we have references too, e.g. suppose I want to print out the list of all the heroes in the game (and I already have handles/references on all these heroes). What would the internals of such a function look like (which natives? do I need to do any type casting to string? etc.)

JASS:
function printUnitName takes unit u returns nothing
...
endfunction

edit: The previous developer of the map I'm doing actually made string arrays for all the names of items, heroes, etc, and then just called these to print the names. That seems a bit silly, surely there is a function that reads a unit/item/etc's name and returns it as a string?
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,337
There are native functions. If using vJass look in the function list.

GetItemName
GetUnitName
GetObjectName
GetPlayerName

I wonder then why the original developer had two string arrays to get the string names of items and heroes. Is there any disadvantage in using these natives? What exactly do they look for in terms of the "name?"
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
I never really used them. I have not heard of anything bad when using them. Also not sure by 2 string array to get them ?

What was done (as far as my understanding of the code) was literally to define each string array's member. Say there are 150 heroes, and each one is mapped to an integer 0-150. Then the hero name array would look like this.

JASS:
globals
string array heroNames
endglobals

function fillArray takes nothing returns nothing
  set heroNames[0] = "Uther"
  set heroNames[1] = "Arthas"
 set heroNames[2] = "Jaina"
  ...
  set heroNames[149] = "Archimonde"
endfunction

That seems silly to do though, if these native functions work just fine...
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
Calling functions is a bit slow. The developer should have but you have not said if the array indizes are mapped to the unit types because there could be other arrays using the same indexing that provide real new data. Or maybe s/he wanted to avoid that you have to access the unit types. Are those the object names or hero proper names? For the proper name, you would have to create an actual unit instance to read it.

Anyway, in this forum you can see people that have got no clue about triggers, and that still import lots of systems. And there lots of ways to realize most things. Do not expect some professional and coherent high quality scripts.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Calling functions is a bit slow. The developer should have but you have not said if the array indizes are mapped to the unit types because there could be other arrays using the same indexing that provide real new data. Or maybe s/he wanted to avoid that you have to access the unit types. Are those the object names or hero proper names? For the proper name, you would have to create an actual unit instance to read it.

Anyway, in this forum you can see people that have got no clue about triggers, and that still import lots of systems. And there lots of ways to realize most things. Do not expect some professional and coherent high quality scripts.

They are the names of the items and the heroes respectively (the object name is the specific name of an instance of a unit, e.g. footman_01 ?).

The same indexing is used throughout the map, e.g. index 0 always maps to attributes of "hfoo:" name, etc. Obviously for items index 0 would map to a different item (since human footman is not an item), but there is an (arbitrary) ordering of all heroes (say 0 - 150) rather than using the unit type directly.

But the author did this throughout for heroes, abilities, and items. I don't think he used an imported system, as he told me himself the code is very very old and written by himself.

Is it worth keeping these string arrays or switching to using native function calls?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Write your own function and do as you please. Since the jass code is not parallel updated to changes in the object editor, it can become nasty. Other than that, I guess there is a lot of information you would want to attach to a unit/read from jass, so you need this structure anyway and then the single attribute is minor.

But having manually assigned an id to each object is indeed ugly and error-prone. You can use allocators like in vJass. Actually, you can make structs like "UnitType" for better readability, control and to easily add new attributes.

GetObjectName refers to an object editor object, not ingame created instances.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
For functions like GetUnitName, GetItemName, I need to pass an actual instance of a unit or object?

What if I want to find out the name of 'hfoo', which is an integer?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can only create an instance of the hero type to randomize one of the proper names (+suffixed number). So yeah, there it would indeed be better to copy the values to jass. There are tools like GMSI that auto-convert object editor data to jass since this is actually a frequent problem.
 
Status
Not open for further replies.
Top