• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Player Selects Unit Trigger - If´/Then/Else not working

Level 15
Joined
Jun 9, 2008
Messages
344

Shortlegs

There's a trigger that devoured too many night hours which I could have used for sleeping.

It's supposed to be a selection trigger - player selects unit, unit is detected as "Triggering Unit" and then used in the rest of the trigger. For testing purposes, I added a "change triggering unit vertex color", to see if it fires at all. It does.

But that's as far as I get: the meat of the trigger is an If/Then/Else function that detects whether any other units surround the triggering (selected) unit. I tried various other conditions, including completely harmless ones like "Is triggering unit alive". But it never works past the If/Then/Else. Anything I put BEFORE that, no issue.

It almost seems like the selection trigger was inherently hostile to If/Then/Else Actions in general.

I'll post the trigger as soon as I can, but you could already help me if you know anything about selection triggers that I might have missed here.
 
I tested with this and it works fine on my end. In what way does it not work? Did you try printing the name of triggering unit after the condition, does it print nothing or the name of a wrong unit?

  • Selection Test
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Set VariableSet temp_loc[1] = (Position of (Triggering unit))
      • Set VariableSet int = 0
      • -------- --------
      • Custom script: set bj_wantDestroyGroup = true
      • -------- --------
      • Unit Group - Pick every unit in (Units within 500.00 of temp_loc[1] matching (((Matching unit) belongs to an enemy of Player 1 (Red).) Equal to True).) and do (Actions)
        • Loop - Actions
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set VariableSet int = (int + 1)
            • Else - Actions
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int Greater than 3
            • Then - Actions
              • Game - Display to (All players) the text: Surrounded
            • Else - Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is alive) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: ((Unit: (Triggering unit)'s String Field: Name ('unam')) + Is Alive)
        • Else - Actions
      • -------- --------
      • Custom script: call RemoveLocation(udg_temp_loc[1])
 
I tested with this and it works fine on my end. In what way does it not work? Did you try printing the name of triggering unit after the condition, does it print nothing or the name of a wrong unit?

  • Selection Test
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Set VariableSet temp_loc[1] = (Position of (Triggering unit))
      • Set VariableSet int = 0
      • -------- --------
      • Custom script: set bj_wantDestroyGroup = true
      • -------- --------
      • Unit Group - Pick every unit in (Units within 500.00 of temp_loc[1] matching (((Matching unit) belongs to an enemy of Player 1 (Red).) Equal to True).) and do (Actions)
        • Loop - Actions
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set VariableSet int = (int + 1)
            • Else - Actions
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int Greater than 3
            • Then - Actions
              • Game - Display to (All players) the text: Surrounded
            • Else - Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is alive) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: ((Unit: (Triggering unit)'s String Field: Name ('unam')) + Is Alive)
        • Else - Actions
      • -------- --------
      • Custom script: call RemoveLocation(udg_temp_loc[1])
Thank you. This is EXACTLY the sort of sample and answer I was hoping for for the purpose of troubleshooting when I posted this thread.
I did in fact do something similar, but yours is much cleaner for demonstration purposes.

After some rest, I discovered that the mistake was ultimately two other things:
  • In one part of the trigger, I left "triggering player" in a condition, even though I should have worked with "owner of triggering unit"
  • The click action is supposed to create a dummy unit with its own variable name. One of the conditions was that I checked whether the map already contains said unit. But it appears that unless the [variable name unit] is already in the map, the trigger cannot check whether "playable map area" contains it, whether it is alive, what its unit type is. So my workaround is that I just kill and recreate that dummy unit every time the base unit is clicked, provided the right structures surround the base structure.
 
Back
Top