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

Units currently selected by player

Status
Not open for further replies.
Level 9
Joined
Oct 20, 2010
Messages
228
Currently, I am creating a command that should work with multiple players. It performs just fine in singleplayer, but the moment two players are typing it I get selection bugs.

What am I misunderstanding?

  • give
    • Events
      • Player - Player 1 (Red) types a chat message containing give as A substring
      • Player - Player 2 (Blue) types a chat message containing give as A substring
      • Player - Player 3 (Teal) types a chat message containing give as A substring
    • Conditions
      • (Substring((Entered chat string), 1, 4)) Equal to give
    • Actions
      • Set VariableSet TempGroup = (Units currently selected by (Triggering player))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup) Greater than 0
        • Then - Actions
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • stuff
          • Custom script: call DestroyGroup (udg_TempGroup)
        • Else - Actions
 
Level 9
Joined
Oct 20, 2010
Messages
228
So the bug comes from this line of code? :
  • TempGroup = (Units currently selected by (Triggering player))
Would this alternative have the same problems if so?
  • Set VariableSet TempGroup = (Units owned by (Triggering player) matching (((Matching unit) is selected by (Triggering player).) Equal to True).)
 
So the bug comes from this line of code? :
  • TempGroup = (Units currently selected by (Triggering player))
Would this alternative have the same problems if so?
  • Set VariableSet TempGroup = (Units owned by (Triggering player) matching (((Matching unit) is selected by (Triggering player).) Equal to True).)

Yeah, they both would have the same issue. You can try creating your own version of the function that doesn't use SyncSelections. Of course it may return the wrong value but in my experience it has been less prone to issues.

JASS:
function GetUnitsSelectedAllEx takes player whichPlayer returns group
    local group g = CreateGroup()
    //call SyncSelections()
    call GroupEnumUnitsSelected(g, whichPlayer, null)
    return g
endfunction

Generally, I try to minimize how often I need to get a player's selected units. If you only need to know if 1 specific unit is selected and aren't dealing with unit groups then the selection event would be better.
 
Status
Not open for further replies.
Top