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

[General] Is there a system that checks "entered region is equal to"

Status
Not open for further replies.
Level 42
Joined
Feb 27, 2007
Messages
5,307
No, unfortunately. You need to manually check if the unit is in each region in a loop. If you have lots of regions and lots of units going through them all the time it's possible this is a performance bottleneck, but you might as well try and see first.
  • Set RegionCount = (RegionCount + 1)
  • Set YourRegion[RegionCount] = The first region <gen>
  • Set RegionCount = (RegionCount + 1)
  • Set YourRegion[RegionCount] = Target Region <gen>
  • Set RegionCount = (RegionCount + 1)
  • Set YourRegion[RegionCount] = Somewhere Else <gen>
  • -------- same for all regions, then this afterward --------
  • For each (Integer A) from 1 to RegionCount do (Actions)
    • Loop - Actions
      • Trigger - Add to REGION_ENTER_TRIGGER <gen> the event (Unit - A unit enters YourRegion[(Integer A)])
  • Events
    • -------- events are added by the other trigger --------
  • Conditions
  • Actions
    • Set EnteredUnit = (Triggering Unit)
    • Set EnteredRegion = No region
    • For each (Integer A) from 1 to RegionCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (YourRegion[(Integer A)] contains EnteredUnit) equal to True
          • Then - Actions
            • Set EnteredRegion = YourRegion[(Integer A)]
            • Custom script: exitwhen true
          • Else - Actions
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • EnteredRegion equal to No region
      • Then - Actions
        • -------- if this is true the game didn't think the unit was in any of the regions so the trigger should end --------
        • Custom script: return
      • Else - Actions
    • -------- From here you can do whatever you want with this information: --------
    • -------- EnteredUnit is the unit that entered --------
    • -------- EnteredRegion is the region that it entered --------
Because of how the enters-region event works with checking if the unit is inside the region, it may be necessary to add a short wait at the start of the second trigger, like so:
  • Actions
    • Wait 0.00 seconds
    • Set EnteredUnit = (Triggering Unit)
    • Set EnteredRegion = No region
 
Level 42
Joined
Feb 27, 2007
Messages
5,307
Yes, it being turn based would reduce the load on the system even with many units like a Risk map would have. I think you can proceed with the system I outlined above, but with a modification:

Instead of just one trigger that runs for every possible region, you should group your regions with similar behavior into their own trigger. So say you have some regions that should teleport units when they enter, those would be their own trigger. Then regions that upgrade units that step in them would have their own trigger. Then regions that redirect/move units to other regions would have their own trigger. I'm just making up examples, your regions might do totally different things since I don't know Risk maps.

Exactly how many triggers and how they are grouped is all up to you, but the purpose of doing this is so that similar regions with similar behavior (when units enter them) will be able to share code that does the same/similar things between them to massively reduce the need for things like If-Then-Else chains like below:
  • If (All conditions are true) then do (Then actions) else do (Else actions)
    • If - Conditions
      • Thing equal to Option_1
    • Then - Actions
      • Do Thing_1
    • Else - Actions
      • If (All conditions are true) then do (Then actions) else do (Else actions)
        • If - Conditions
          • Thing equal to Option_2
        • Then - Actions
          • Do Thing_2
        • Else - Actions
          • If (All conditions are true) then do (Then actions) else do (Else actions)
            • If - Conditions
              • Thing equal to Option_3
            • Then - Actions
              • Do Thing_3
            • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,378
@Pyrogasm Don't get me mad but i don't understand what is happening in your first trigger (you first post). I don't understand anything in there. If you remember me, i was the one who has low IQ. The systems like this exceeding my limits.
His first trigger shows you how to store your Regions into a Region array variable. You would want to do this during Map Initialization (the loading screen) since you're going to use these variables later on:
  • Events
    • Map initialization
  • Actions
    • Set YourRegion[1] = The first region <gen>
    • Set YourRegion[2] = The second region <gen>
    • Set YourRegion[3] = The third region <gen>
YourRegion is the Region array variable. As you can see it's being Set to multiple Regions that you have created for your map. You can name the YourRegion variable to anything you want, maybe CountryRegion would make more sense if you wanted each Region to represent a different country. If you don't understand how Arrays work then you should spend some time researching them. They're necessary to make advanced triggers.

His second trigger shows you how to take advantage of this Region variable in order to answer your question:

Is there a system that checks "entered region is equal to"​


You can see that he is using a For Loop that loops over all of the different Regions that you've stored in the YourRegion variable. If you don't understand what a For Loop does then you should research it as well. Then the trigger checks each Region to see if the (Entering unit) is in it. Note that (Triggering unit) is the same exact thing as (Entering unit). Finally, he uses two variables, EnteredUnit and EnteredRegion, which as explained by the comments are going to be Set to the proper Unit/Region if all was successful.

So at the end of that second trigger you can use the EnteredRegion variable to reference the Region that the EnteredUnit entered:
  • Unit - Create 1 Footman for (Owner of (EnteredUnit)) at (Center of EnteredRegion)...

You can then expand upon this system by creating other Array variables associated with your Regions. For example, an Income system that adds a different amount of Gold for each Country:
  • Player - Add CountryIncome[(Integer A)] to (Owner of (EnteredUnit)) Current gold
(Integer A) is the [index] of the Region that the unit entered. I recommend using your own Integer variable here but it's fine for now.
 
Last edited:
Level 18
Joined
Jun 2, 2009
Messages
1,205
Dear @Uncle and dear @Pyrogasm i have read your messages 5 times. And still i don't understand most of the parts of this trigger. This is what i am trying to say. All people have their own limits and it seems trigger above my limits.

Is there an easy way to do that?

For the being specific i can ask every questions.

Who is the entered unit

Why are we setting EnteredRegion = No Region

What does it means
joinminus.gif
if.gif
For each (Integer A) from 1 to RegionCount do (Actions)

Why we are checking this
if.gif
(YourRegion[(Integer A)] contains EnteredUnit) equal to True

Why we are setting entered region as this
set.gif
Set EnteredRegion = YourRegion[(Integer A)]

What is this doing
page.gif
Custom script: exitwhen true

Why we are checking is EnteredRegion equal to No Region?
if.gif
EnteredRegion equal to No region

What is this doing
page.gif
Custom script: return

It sets RegionCount for every region i set there and if it is 80 regions, that means RegionCount = 80
I don't understand what is happens in here

What is Integer A and what happens from 1 to 80 in here? And what is this Add to Region Enter Trigger does? I have never used this before.
For each (Integer A) from 1 to RegionCount do (Actions)
Loop - Actions
Trigger - Add to REGION_ENTER_TRIGGER <gen> the event (Unit - A unit enters YourRegion[(Integer A)])

Currently i am detecting which unit entered which region and conquer just like this. Basically unit casts Storm Bolt to enemy, and removes targeted unit from the game and moves the their region.

  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Storm Bolt 1
  • Actions
    • Set TempUnitTarget = (Target unit of ability being cast)
    • Set TempPoint = (Position of (Casting unit))
    • Set TempPoint2 = (Position of (Target unit of ability being cast))
    • Unit - Move (Casting unit) instantly to TempPoint2
    • Unit - Remove TempUnitTarget from the game
    • Set TempUnitTarget = No unit
    • Custom script: call RemoveLocation (udg_TempPoint)
    • Custom script: call RemoveLocation (udg_TempPoint2)
And this trigger checks which region entered, changes DummyTower[2] ownership to the player who conquers.

  • Events
    • Unit - A unit enters test2 <gen>
  • Conditions
    • (Triggering unit) Equal to TempUnitCaster
  • Actions
    • Set TempUnitCaster = No unit
    • Unit - Change ownership of DummyTower[2] to (Owner of TempUnitCaster) and Change color
 

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,378
To answer some questions (although I think a lot of the answers are provided already):

1) EnteredUnit is the unit that entered the region. This would either be the (Entering unit) or the (Triggering unit) - these are the same thing. You technically don't have to use this variable but it helps make the trigger run better.

2) EnteredRegion is set to No Region at first, BUT if your unit is in one of YourRegions then it will be Set to that Region instead. Pyro does this because later on in the trigger he checks the value of EnteredRegion and if it's still Equal to No Region then he skips the rest of the trigger. In other words, if for some reason the Unit isn't in ANY of these Regions then nothing should happen.

3) That's a For Loop, again you should look it up as it's a pretty common thing to use and you NEED to learn how it works or you won't get anywhere. In this case it allows us to check every single Region stored in the YourRegion array.

4) We want to know if the (Entering unit), aka EnteredUnit, is inside of one of YourRegions. In order to do that, you use the Condition "Region contains unit" which will either be True or False depending on whether or not the Unit is inside of said Region.

5) EnteredRegion is the Region that the unit entered. It's Set here because the Condition was true, the unit was indeed inside of YourRegion[(Integer A)]. From this point on in the trigger you can now reference the EnteredRegion variable to get the Region the unit entered.

6) Custom script: exitwhen true is used to stop the For Loop early since we've successfully found the Region that the unit entered. It will make more sense once you understand how For Loops work.

7) This is the reason why EnteredRegion was set to No Region at first. This will skip the rest of the trigger if EnteredRegion is still Equal to No Region, which it will be IF it couldn't find a Region that contains the entering unit.

8) Custom Script: return is the same thing as this:
  • Skip remaining actions
It stops the trigger early, in this case because the Unit wasn't in any of YourRegions.

9) Let's say you have 80 Countries in your game, in other words 80 Regions. This RegionCount variable is used to keep track of how many Regions you have and works with the For Loop in order to make sure that you check all 80 Regions -> 1 to 80. If you had 80 Regions, but only Looped from 1 to 10, then only the first 10 Regions would be checked and the other 70 would be ignored.

Again, there's a lot of information on For Loops regarding how they work. I recommend creating a new map and messing around with them until you understand how they work. There's a lot of good information on this site that can help you out as well. Find and recreate some trigger examples and then ask yourself "Why does this work?". Displaying Text Messages can help explain a lot, for example I recommend displaying the (Integer A) variable inside of a For Loop so you can see what it's doing. You can even check out tutorials on youtube about For Loops since they're used outside of Warcraft 3.

Trigger - Add to REGION_ENTER_TRIGGER <gen> the event (Unit - A unit enters YourRegion[(Integer A)]) is used to Add the "A unit enters Region" Events to your trigger. This is a shortcut that makes it so you don't have to Add all 80 Regions to the Events of your trigger manually, because this can be a real pain in the ass if you have 80 Regions:
  • Events
    • Unit - A unit enters Region 1
    • Unit - A unit enters Region 2
    • Unit - A unit enters Region 3
    • Unit - A unit enters Region 4
    • Unit - A unit enters Region 5
    • etc...
 
Last edited:
Level 18
Joined
Jun 2, 2009
Messages
1,205
You are simply amazing dear @Uncle but i have realized still it is beyond my limits. It is not about you. It is about me.
I have read your post few times and still i do not understand what is going on this trigger.
I understand few things in your post but still i don't understand the trigger.

This system beyonds my limits and knowledge, i will look for simple solution for that. I give up.
Thank you for everything. I am sorry. Being stupid was not my choice. I would like to be someone like you.
 
Level 42
Joined
Feb 27, 2007
Messages
5,307
I have read your post few times and still i do not understand what is going on this trigger.
I understand few things in your post but still i don't understand the trigger.
Is it a language or translation issue that makes understanding triggers difficult for you? Türkçe konuştuğunu biliyorum, so I can only assume that your World Editor language is also set to Turkish. I guess that you must translate the text of each line of triggers that we write from English into Turkish (which might not produce the same exact words GUI uses in the Turkish language version), then try to understand what it means, and then go recreate that line in the Turkish WE. Good luck looking at multiple lines at a time and hoping the translation is right!

That seems like a lot of work and I can understand why you feel you don't understand anything. Maybe there is a solution that would make triggers easier to understand for you. I have a few ideas. Maybe one of them will help, or you will have your own idea about what to do:
  • Change your World Editor language to English (or install English and Turkish WE at the same time) so you can easily look for exactly the same words as we are using in our example triggers instead of hoping the translations from EN to TR match up. If you spend more time using the English WE you will get more familiar with the EN words used everywhere and you might become better at recognizing what a trigger (or some lines of a trigger) is trying to accomplish.

  • Because Uncle's help seems to help you, when we give example triggers to show a possible solution we must upload example maps that you can open in the Turkish WE (where the triggers will appear properly translated from EN to TR). Then you can see exactly how they translate and read in your native language easily. As you see more translations you will become more familiar. The downside of this approach is that, for example, I can't reply to your threads from my phone because I cannot open and make WE maps from my phone.

  • Make a list of common words or phrases you see us use in triggers and write down what they mean in Turkish so you can easily look up 80% of the relevant trigger language without having to worry about translation.
Why am I suggesting this? Triggers are very logical. 95% of the time they only do exactly what they say they are going to do, in exactly the order they show that they are going to do those things. If you want to understand what a trigger does, you simply need to read each line from top to bottom with the knowledge that each line happens immediately after the one above it until the trigger is 'finished'. The reasons why a trigger has been written the way it is are probably harder to understand, but to even attempt that you have to know what the trigger does in the first place!

So you should focus on understanding the what by reading through triggers line by line like you would a book. Really take your time and be slow about it. Ask yourself questions like: Is this line an action, event, condition, something else? What does this line say it does first? What options does it say it uses/has? Are there any inherent conditions? It probably sounds silly to say these questions out loud or even think them, but if you do not engage with this thought process you literally can't ever know what the trigger does. The best way to test your comprehension/understanding is to ask the question "What would happen if I deleted or disabled this line right now?"

You need practice, JFAMAP. You need to read and understand many simple triggers to get better at understanding bigger more complex triggers. It's possible that language/translation is a big problem to resolve, so if that's the case I invite you to explore the suggestions I gave above. Tell me how I can help you. Even when I am mad at you, I don't think you're too stupid to understand; I think you don't have the skills to be successful yet and you need to grow them.
 
Last edited:
Level 18
Joined
Jun 2, 2009
Messages
1,205
First of all thank you too @Pyrogasm Yes honestly language barries is a problem to me. But i am using every software in English. I would like to explain everything that i don't understand but i do not want to to bother both of you anymore. I have partially understand about the trigger. But partially doesn't provide me any result. I have stucked at the very beginning because there are no entered unit available but still we are able to detect without event. It was just one example.

I am 37 years old man, created many maps and systems since 2002 and still there are lot of things that i don't understand in World Editor. But my skills we're sufficient enough to create many maps. But sometimes i was need some of the systems i have to learn how them works for my maps. I have learned some of them, and some of them not.

You guys can understand anything you see in your lifetime? It is not works for me. There are many things i don't understand and this system is one of them. I believe sometimes we should accept our own limits and know where to stop.
 

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,378
So you say:
"I have stucked at the very beginning because there are no entered unit available but still we are able to detect without event"
But understand that there are Events, you just can't see them because they're being Added to the trigger using a special Action:
  • Loop - Actions
    • Trigger - Add to REGION_ENTER_TRIGGER <gen> the event (Unit - A unit enters YourRegion[(Integer A)])
I took this from his very first trigger where all of the variables that the system uses are Set. You don't have to always Add Events manually, you can use Actions to Add Events to a trigger as well. Like I said before, this is useful since you may have A LOT of Events and adding them yourself the normal way can be a pain.

So if it helps, just imagine that his second "region" trigger has these Events:
  • Events
    • Unit - A unit enters YourRegion[1]
    • Unit - A unit enters YourRegion[2]
    • Unit - A unit enters YourRegion[3]
    • Unit - A unit enters YourRegion[4]
    • Unit - A unit enters YourRegion[5]
    • -------- The For Loop adds these regions all the way up to YourRegion[80] --------
Then looking at the actions in this trigger, you can see that Pyro Sets two variables for you to use, EnteredUnit and EnteredRegion. The (Triggering unit), which is the same exact thing as (Entering unit), is Set to be equal to EnteredUnit:
  • Set EnteredUnit = (Triggering unit)
  • Set EnteredRegion = No region
You don't NEED to use that EnteredUnit variable, you can still use the (Entering unit) or (Triggering unit) Event Responses to interact with the Unit that entered the Region. But you do NEED to use the EnteredRegion variable if you want to interact with the Region that the Unit entered.

Then I believe that you're confused because EnteredRegion is Set to No region, but understand that it's only Set to No region at the start of the trigger. By the end of the trigger, if a Region was found, it will be equal to the Region that the unit entered.

All of the comments in Pyro's trigger help explain this, and in case you were wondering, these are comments:
  • -------- From here you can do whatever you want with this information: --------
A Comment is an Action that allows us to leave notes for ourselves/others to help explain what's happening in our triggers. You can write anything you want in a Comment:
  • -------- hello JFAMAP. Pyro made these comments to help you. --------
Remember, a trigger happens from top to bottom so the order of the Conditions/Actions can be very important. In Pyro's trigger he does this:
Top of trigger = This is where Pyro sets some important variables and finds which region was entered.
Bottom of trigger = This is where YOU would then add your own Actions for what you want to happen.

So let's say you wanted to Create a Unit at the Region that the unit entered. You would do it like this:
  • Events
    • -------- events are added by the other trigger --------
  • Conditions
  • Actions
    • Set EnteredUnit = (Triggering Unit)
    • Set EnteredRegion = No region
    • For each (Integer A) from 1 to RegionCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (YourRegion[(Integer A)] contains EnteredUnit) equal to True
          • Then - Actions
            • Set EnteredRegion = YourRegion[(Integer A)]
            • Custom script: exitwhen true
          • Else - Actions
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • EnteredRegion equal to No region
      • Then - Actions
        • -------- if this is true the game didn't think the unit was in any of the regions so the trigger should end --------
        • Custom script: return
      • Else - Actions
    • -------- From here you can do whatever you want with this information: --------
    • -------- EnteredUnit is the unit that entered --------
    • -------- EnteredRegion is the region that it entered --------
    • Unit - Create 1 Footman for Player 1 - Red at (Center of EnteredRegion)
 
Last edited:

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,378
Here's the map, you'll notice the triggers are slightly different from what we showed you before. This is because I added a fix to the Regions which makes them work properly. This added some new Actions and got rid of some unnecessary Actions.

Not a lot of people realize this but GUI Regions are actually broken by default and have the incorrect x/y coordinates. As a result they'll always be slightly off and cause Conditions like (Region contains Unit/Point) to fail even though the Unit/Point is clearly inside of it.
 

Attachments

  • Region Example 1.w3m
    18.9 KB · Views: 4
Last edited:
Status
Not open for further replies.
Top