Is this trigger optimized? xD

Status
Not open for further replies.
Level 4
Joined
Dec 29, 2009
Messages
69
  • Orc spawn
    • Events
      • Time - Every 45.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Troll Headhunter for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 2 Raider for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Troll Headhunter for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 2 Raider for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Troll Headhunter for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Set OrcSpawn = (Random point in Orc spawn <gen>)
      • Unit - Create 2 Raider for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Custom script: call RemoveLocation (udg_OrcSpawn)
If i just use 1 Set variable action they will all spawn in the same spot
 
Level 3
Joined
Feb 8, 2010
Messages
34
Do you mean that if you use
  • Actions
    • Unit - Create 5 Grunt for Player 2 (Blue) at (Random point in your region <gen>) facing 270.00 degrees
    • Unit - Create 5 Grunt for Player 2 (Blue) at (Random point in your region <gen>) facing 270.00 degrees
    • Unit - Create 5 Grunt for Player 2 (Blue) at (Random point in your region <gen>) facing 270.00 degrees
    • Unit - Create 5 Grunt for Player 2 (Blue) at (Random point in your region <gen>) facing 270.00 degrees
    • Unit - Create 5 Grunt for Player 2 (Blue) at (Random point in your region <gen>) facing 270.00 degrees
they all spawn in the same place?
 
Level 4
Joined
Jan 9, 2010
Messages
89
It still leaks. You would have to remove the location every time, not just once. That is exactly what leaks are, you set a variable with something, then set it with something else, then the first thing will still be there, unaccessible, so remove before seting it again.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Use a loop for doing things that are virtually the same. Example:
  • For each (Integer A) from 1 to 9, do (Actions)
    • Loop - Actions
      • Set OrcSpawn = (Random point in (OrcSpawn <gen>))
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
      • Custom script: call RemoveLocation (udg_OrcSpawn)
I'm not sure about the location leak though since I usually code in vJass.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
It's not optimized at all :p
  1. The first units will spawn at the center of the map, since the location isn't defined yet.
  2. You could use a loop
  3. There are leaks (it's the same region, but a random point within that region, thus a different location).

This creates:
  • 3x 3 Grunts
  • 9x 5 Grunt
  • 3x 2 raider
  • 3x 5 headhunter

Better version:

  • Orc Spawn
    • Events
      • Time - Every 45.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer LoopInt) from 1 to 9, do (Actions)
        • Loop - Actions
          • Set OrcSpawn = (Random point in Orc spawn <gen>)
          • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
          • Custom script: call RemoveLocation(udg_OrcSpawn)
      • For each (Integer LoopInt) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set OrcSpawn = (Random point in Orc spawn <gen>)
          • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
          • Custom script: call RemoveLocation(udg_OrcSpawn)
      • For each (Integer LoopInt) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set OrcSpawn = (Random point in Orc spawn <gen>)
          • Unit - Create 2 Raider for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
          • Custom script: call RemoveLocation(udg_OrcSpawn)
      • For each (Integer LoopInt) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set OrcSpawn = (Random point in Orc spawn <gen>)
          • Unit - Create 5 Troll Headhunter for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
          • Custom script: call RemoveLocation(udg_OrcSpawn)
Well, I could still improve it so it's only 1 loop (from 1 to 9) and if LoopInt < 4, create everything, else only create the 5 grunts, but this is easier to modify I think
 
Level 5
Joined
May 31, 2009
Messages
122
Use a loop for doing things that are virtually the same. Example:
  • For each (Integer A) from 1 to 9, do (Actions)
    • Loop - Actions
      • Set OrcSpawn = (Random point in (OrcSpawn <gen>))
      • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
I'm not sure about the location leak though since I usually code in vJass.

Just add the jass thing to the loop, and that solves the problem.
 
Level 4
Joined
Dec 29, 2009
Messages
69
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
  • Loop - Actions
  • Set OrcSpawn = (Random point in Orc spawn <gen>)
  • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
  • Custom script: call RemoveLocation(udg_OrcSpawn)
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
Would this create 9 Grunts in the same place? cos i want them to be as scattered as possible when they spawn, so 3 groups of 3 would be better

@grimreaper: No i meant having a trigger like this

  • Set OrcSpawn = (Random point in Orc spawn <gen>)
  • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
  • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
  • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
  • Unit - Create 5 Grunt for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
  • Custom script: call RemoveLocation (udg_OrcSpawn)
Would make them all spawn in the same place
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
  • Loop - Actions
  • Set OrcSpawn = (Random point in Orc spawn <gen>)
  • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
  • Custom script: call RemoveLocation(udg_OrcSpawn)
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
Would this create 9 Grunts in the same place? cos i want them to be as scattered as possible when they spawn, so 3 groups of 3 would be better
It shouldn't because OrcSpawn will be set to a random point in the region every time the loop is executed. You could also test it out by yourself as the trigger was provided to you.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
  • Loop - Actions
  • Set OrcSpawn = (Random point in Orc spawn <gen>)
  • Unit - Create 3 Grunt for Player 2 (Blue) at OrcSpawn facing 0.00 degrees
  • Custom script: call RemoveLocation(udg_OrcSpawn)
  • For each (Integer LoopInt) from 1 to 3, do (Actions)
Would this create 9 Grunts in the same place? cos i want them to be as scattered as possible when they spawn, so 3 groups of 3 would be better
No: that creates 3 groups of 3 grunts at a different location.
It just loops that action 3 times, so it sets up a different location 3 times.
 
If you don't want to use JASS, simply make a seperate trigger called "spawners". This trigger will look like:
  • Spawn Trigger
  • Actions
    • Set OrcSpawn = (Random point in Orc spawn <gen>)
    • Unit - Create (udg_i) (udg_type) for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
    • Custom Script: call RemoveLocation(udg_OrcSpawn)
Now in your main trigger, you simply define:
  • Actions
    • set (udg_i) = (the number of units you want to make)
    • set (udg_type) = (the type of unit you want to make)
    • Trigger - Run SpawnTrigger
and do that for each type. That's an efficient GUI code, imo.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
If you don't want to use JASS, simply make a seperate trigger called "spawners". This trigger will look like:
  • Spawn Trigger
  • Actions
    • Set OrcSpawn = (Random point in Orc spawn <gen>)
    • Unit - Create (udg_i) (udg_type) for Player 2 (Blue) at OrcSpawn facing 270.00 degrees
    • Custom Script: call RemoveLocation(udg_OrcSpawn)
Now in your main trigger, you simply define:
  • Actions
    • set (udg_i) = (the number of units you want to make)
    • set (udg_type) = (the type of unit you want to make)
    • Trigger - Run SpawnTrigger
and do that for each type. That's an efficient GUI code, imo.
...but not exactly what he wanted, as he wanted to make several groups scattered across the map, not one giant group.
Also, instead of using several variables, what's wrong with simply defining those values in the main trigger itself?

Why would you use variables if the unit type/amount isn't going to change anyway? :/
I think it's a waste of variables.

He also wants several unit types, so you either have to change the variable in the main trigger, after one unit type spawned, or just insert it in the action "create unit", which gives the exact same result, with the difference that it needs more lines with the variables and well... it needs variables, obviously.

Sorry to ruin your idea though :D
 
nah it's what blizzard did when they made WarChasers. It works, and what I was saying is use those three lines (number units, type unit, call trigger) over and over again in the main trigger. If he wants to put each unit in a different random place (by what you say) then yeah use a loop and instead of using the integer variable just assign the endloop to that variable.
 
Status
Not open for further replies.
Top