• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

How to use Variables to reference a particular unit?

Status
Not open for further replies.
Level 3
Joined
May 27, 2023
Messages
10
Hello! I am a new to world edit and I am currently creating a campaign map in World Editor and I've come to a problem with finding a particular unit. The map is your typical wave survival map, but I've added complexity to it by making the enemy waves also attack small isolated allied villages on the map. If the player chooses not to protect these villages, an enemy building will be built which will create more enemy waves.

The problem now lies in how do I reference this particular building once its built. I don't have a fixed trigger made yet but the general idea is like this...

Trigger 1 "Village 1 fallen"
--Event--
Unit - Town Hall Dies
--Action--
Unit - Move "Peon" to "Village 1 Area"
Unit - Order "Peon" to build Stronghold at (Center of "Village 1 Area)


Triggers 2 "Establish Base"
--Event--
Unit - A unit finishes construction
--Condition--
Owner & Unit-type = Player 11 & Stronghold
--Action--
Set "Triggering Unit" AS "Village 1 reference")
Trigger - Turn On ("Attack Waves")


Trigger 3 "Retake Village"
--Event--
Unit - "Village 1 reference" Dies
--Action--
Trigger - Turn off ("Attack Waves")


I'm confused as to how I can reference this particular building once its built. The issue arises when there will be multiple of these same strongholds built at different times, so how can I differentiate village 1 stronghold with village 2 stronghold when the player comes to destroy and recapture it? I know the solution would be to use variables, but when I try setting it, and referencing it in the event or conditions, I can't find my unit variable. Can anyone point me in the right direction?


Thank you!
 

Uncle

Warcraft Moderator
Level 68
Joined
Aug 10, 2018
Messages
7,109

You can track the Stronghold using a Unit variable like this:
  • Get Stronghold
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Stronghold
      • (Owner of (Triggering unit)) Equal to Player 11 (Dark Green)
    • Actions
      • Set VariableSet MyStronghold = (Triggering unit)
(Triggering unit) is always equal to the unit mentioned in the Event (A unit does blah blah blah).

You can then reference your Unit variable with a Unit condition:
  • Stronghold Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Triggering unit) Equal to MyStronghold
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: The Stronghold died!
You can also detect when ANY Stronghold dies by referencing a Unit-Type rather than a Unit:
  • Stronghold Dies Copy
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Stronghold
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: A Stronghold died!
I can't find my unit variable
Perhaps you're making the mistake of using Specific Events instead of Generic Events. You would want to use Generic when working with variables.

The next thing I recommend you try to master is Unit Group variable as they give you a lot of control over multiple units at once. Then down the line once you're more comfortable you should learn how to use Arrays (a special option for Variables). These will allow you to create more dynamic triggers and use advanced methods like Unit Indexing and Dynamic Indexing.
 
Last edited:
Status
Not open for further replies.
Top