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

How to reference a <gen> unit variable in JASS?

Status
Not open for further replies.
Level 21
Joined
Mar 16, 2008
Messages
964
I found a piece of code that needs to be added to my map but I want it to reference a specific unit in my map, CASTLE 0012 <gen>, and not triggering unit. Can anyone help me with this? Can't find the answer on any guide.

  • call IssueImmediateOrderById(GetTriggerUnit(), 851976)

edit: my goal here to is cancel a 2nd trained hero after the first one is trained, if the player queues up two, then it limits heroes. hope that makes sense. the above call command is supposed to issue 'esc' key stroke, cancelling training of the 2nd hero.
 
Last edited:
Level 23
Joined
Dec 4, 2007
Messages
1,559
You can make it work like this:
Set VariableSet u = CASTLE 0012 <gen>
Custom script: call IssueImmediateOrderById(udg_u, 851976)

u is simply a unit global variable
 
Level 21
Joined
Apr 12, 2018
Messages
494
If you really have to do it that way, make a dummy trigger with an Action that refers to that preplaced unit and then just convert to custom script. It'll show you what it's being called.
 
Level 24
Joined
Jun 26, 2020
Messages
1,928
The thing with JASS is the unit must have be referenced first in a GUI trigger to have its ID, it should like "Paladin 0001", so that 0001 is the ID (you can delete that trigger after, except if you use Lua, in that case the trigger must exist, but you can turn it off because deactiving it doesn't count).
When you have the ID you must look their unit-type ID or destructable or item (you should look it in the editor and press Ctrl+D), then look what type of object this to get the prefix (if is a unit, the prefix is unit; if is an item, item, if is a destructable, dest), then the generated variable should look like this:
"gg_<Object prefix><ID of the type><ID of the object>", example, if is a peasant called "Peasant 0000", is a unit and its ID is 'hpea' so the generated variable would be: gg_unit_hpea_0000
 
Last edited:
Level 21
Joined
Mar 16, 2008
Messages
964
Update:
I finally mustered the energy to try n implement this. Maybe I'm not understanding the first part of your post about getting the unit ID. Maybe I should just do it the way with the duplicate GUI variable.

This seems to not work:
  • Custom script: call IssueImmediateOrderById (gg_unit_hcas_0012, 851976)
hcas_0012 is a pre-exiting castle unit on the map.

where as this seems to work with the GUI variable.
  • Custom script: call IssueImmediateOrderById (udg_King_Castle_Var_Red, 851976)
I'll just do it the GUI way but any additional constructive comments would be welcomed.
 
Status
Not open for further replies.
Top