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

Why are these triggers spawning the Orcs in the center of the map?

Level 5
Joined
Mar 10, 2021
Messages
24
  • TurnOnSpawn
    • Events
      • Time - Elapsed game time is 25.00 seconds
    • Conditions
    • Actions
      • Trigger - Turn on ChooseSpawn <gen>
      • Trigger - Turn on DoSpawn <gen>
      • Quest - Display to (All players) the Quest Update message: |cffffcc00The Orcs ...
      • Set VariableSet OrcBaseCount = (Random integer number between 1 and 4)
      • Set VariableSet BaseOrcRegion[OrcBaseCount] = BaseOrcSpawn
  • ChooseSpawn
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OrcBaseCount Less than 4
        • Then - Actions
          • Set VariableSet OrcBaseCount = (OrcBaseCount + 1)
          • Set VariableSet BaseOrcSpawn = BaseOrcRegion[OrcBaseCount]
        • Else - Actions
          • Set VariableSet OrcBaseCount = (Random integer number between 1 and 4)
          • Set VariableSet BaseOrcSpawn = BaseOrcRegion[OrcBaseCount]
  • DoSpawn
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Create 1 OrcTypes[(Random integer number between 1 and 5)] for Player 6 (Orange) at (Center of BaseOrcSpawn) facing Default building facing degrees
I set the variable in the initialization to be anything other than 0, so why is this not working?

EDIT: I also switched the definitions between the BaseOrcRegion[X] and BaseOrcSpawn definitions in the first trigger, same thing.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,587
So in TurnOnSpawn you're setting BaseOrcRegion[random number] to be equal to BaseOrcSpawn. As far as I can tell, BaseOrcSpawn isn't set to anything yet, so nothing is happening here. You're setting a Region variable that is currently tracking nothing to be equal to nothing. The end result, it's still tracking nothing.

Then when you attempt to create a Unit at a Point that doesn't exist (the center of a non-existent region) it'll instead default to the center of the map. This is a safety precaution that ensures that you always Create the unit even if you fail to provide a valid Point to create it at.


I'm going to assume that you have four different bases (regions) that you want to spawn units at. Here's how you can fix your triggers:

1) Create a Point array variable. Let's call it BaseOrcSpawnPoint.

2) Delete the BaseOrcSpawn variable, it's unnecessary.

3) Edit TurnOnSpawn to do the following:
  • TurnOnSpawn
    • Events
      • Time - Elapsed game time is 25.00 seconds
    • Conditions
    • Actions
      • Trigger - Turn on ChooseSpawn <gen>
      • Trigger - Turn on DoSpawn <gen>
      • Quest - Display to (All players) the Quest Update message: |cffffcc00The Orcs ...
      • Set VariableSet BaseOrcSpawnPoint[1] = (Center of BaseOrcRegion1 <gen>)
      • Set VariableSet BaseOrcSpawnPoint[2] = (Center of BaseOrcRegion2 <gen>)
      • Set VariableSet BaseOrcSpawnPoint[3] = (Center of BaseOrcRegion3 <gen>)
      • Set VariableSet BaseOrcSpawnPoint[4] = (Center of BaseOrcRegion4 <gen>)
      • Set VariableSet OrcBaseCount = (Random integer number between 1 and 4)
You now have a Point variable tracking the center of each base.

4) Edit ChooseSpawn to do the following:
  • ChooseSpawn
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OrcBaseCount Less than 4
        • Then - Actions
          • Set VariableSet OrcBaseCount = (OrcBaseCount + 1)
        • Else - Actions
          • Set VariableSet OrcBaseCount = (Random integer number between 1 and 4)
5) Edit DoSpawn to do the following:
  • DoSpawn
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Create 1 OrcTypes[(Random integer number between 1 and 5)] for Player 6 (Orange) at BaseOrcSpawnPoint[OrcBaseCount] facing Default building facing degrees
Units are created at Points, not Regions, so it makes sense to use a Point array variable rather than a Region array variable. Also, you don't need the BaseOrcSpawn variable since you can just reference the Point and it's [index] directly in the spawn trigger.

This design even avoids a memory leak due to how we're using a Point variable rather than (Center of region) in the Spawn trigger.
 
Last edited:
Level 5
Joined
Mar 10, 2021
Messages
24
So in TurnOnSpawn you're setting BaseOrcRegion[random number] to be equal to BaseOrcSpawn. As far as I can tell, BaseOrcSpawn isn't set to anything yet, so nothing is happening here. You're setting a Region variable that is currently tracking nothing to be equal to nothing. The end result, it's still tracking nothing.

Then when you attempt to create a Unit at a Point that doesn't exist (the center of a non-existent region) it'll instead default to the center of the map. This is a safety precaution that ensures that you always Create the unit even if you fail to provide a valid Point to create it at.
"I set the variable in the initialization to be anything other than 0, so why is this not working?"

"EDIT: I also switched the definitions between the BaseOrcRegion[X] and BaseOrcSpawn definitions in the first trigger, same thing."

I appreciate all the effort you went through but those were of the only things I said in the post.

I began to use units (structures) instead of regions with the trigger (spawn at region centered on position of unit) which worked, so i think it might simply be broken.

Something about defining regions with the Array was what was broken. I'm not sure why but if I set BaseOrcSpawn to any of the BaseOrcRegion array, the trigger would simply fail and they'd spawn in the center.

No matter how hard I forced it, the region array would return a 0 to the BaseOrcSpawn. So I switched to using structures and instead of picking a region, it picks a structure, and I use that structure's position. Worked as planned.

I think it was simply broken, try to define a variable region by a region array.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,587
"I set the variable in the initialization to be anything other than 0, so why is this not working?"

I appreciate all the effort you went through but that was one of the only things I said in the post.

I began to use units (structures) instead of regions with the trigger (spawn at region centered on position of unit) which worked, so i think it might simply be broken.

Something about defining regions with the Array was what was broken. I'm not sure why but if I set BaseOrcSpawn to any of the BaseOrcRegion array, the trigger would simply fail and they'd spawn in the center.

No matter how hard I forced it, the region array would return a 0 to the BaseOrcSpawn. So I switched to using structures and instead of picking a region, it picks a structure, and I use that structure's position. Worked as planned.

I think it was simply broken, try to define a variable region by a region array.
Region arrays may need to be initialized (you would set the initial size through the variable editor) but I don't recall this being the case. I know for a fact that you have to do this for Timers, Unit Groups, and Player Groups (although, technically you can use Custom Script to bypass this limitation by creating said objects yourself). Anyway, I was struggling to word this properly so I'll try again.

What is BaseOrcSpawn set to in this first trigger?
  • TurnOnSpawn
    • Actions
      • Set VariableSet OrcBaseCount = (Random integer number between 1 and 4)
      • Set VariableSet BaseOrcRegion[OrcBaseCount] = BaseOrcSpawn
This doesn't make any sense if BaseOrcSpawn isn't set to anything.

Also, where are you setting up the BaseOrcRegion array? Do you have some kind of setup trigger that is running beforehand? For example:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set Variable BaseOrcRegion[1] = some region <gen>
    • Set Variable BaseOrcRegion[2] = some region <gen>
    • Set Variable BaseOrcRegion[3] = some region <gen>
    • Set Variable BaseOrcRegion[4] = some region <gen>
What you're doing doesn't really make any sense without this step.

Maybe I'm just misunderstanding but it appears to me like you're making some fundamental mistakes.

[ Edit ]

I've tested it out on the latest patch and have confirmed that Region arrays work properly. I think you may have forgotten to setup your Array which is why it didn't work for you. Here are the triggers I used to test it:
  • Setup Regions
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet My_Region_Array[1] = R1 <gen>
      • Set VariableSet My_Region_Array[2] = R2 <gen>
      • Set VariableSet My_Region_Array[3] = R3 <gen>
      • Set VariableSet My_Region_Array[4] = R4 <gen>
  • Test Regions
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet My_Region = My_Region_Array[(Random integer number between 1 and 4)]
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of My_Region) facing Default building facing degrees
 

Attachments

  • Region Array Example.w3m
    17.7 KB · Views: 0
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,587
yeah no it's been set in another trigger as per what I said in the initial post, I figured it out and thank you for trying, but that was not the issue.
So what was the issue then? Because what you were trying to do with the Region variables definitely works, there is no bug here.

I'm just curious at this point and it'd be nice clarification for others that stumble upon this.

Also, I still insist on using my original method since it avoids a memory leak when you create the unit. This is because (Center of region) and (Position of unit) both leak without a Point variable.
 
Last edited:
Top