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

[Solved] Create unit for each player only creates 1

Status
Not open for further replies.
Level 3
Joined
Nov 13, 2010
Messages
6
  • Shit Is Broken
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Unit - Create 1 PICK for (Picked player) at (Center of (Playable map area)) facing Default building facing degrees
          • Set VariableSet PickerUnit[(Player number of (Picked player))] = (Last created unit)
So, this just doesn't seem to work properly as it only creates unit for player one and not any other unit.
I have tested it with variety of changes and nothing seems to work ( at least not when i need it ).

"Players" does contain every player ( that is playing, tested it multiple times ) and it works with seemingly every other function ( have not encountered it breaking elsewhere ). I have managed to work around the problem in less pleasing way.
A snippet of how it was used initially. This also has the for loop that I am using to bypass the issue.
  • PickingCreateTaven
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from (Center of (Playable map area)) to a radius of 512.00.
      • Unit - Create 1 Portal for Neutral Passive at (Center of (Playable map area)) facing Default building facing degrees
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Camera - Pan camera for (Picked player) to (Center of (Playable map area)) over 0.00 seconds
          • Selection - Select (Last created unit) for (Picked player)
      • -------- THE SHIT IS BROKEN --------
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Unit - Create 1 PICK for (Picked player) at (Center of (Playable map area)) facing Default building facing degrees
          • Set VariableSet PickerUnit[(Player number of (Picked player))] = (Last created unit)
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) slot status) Equal to Is playing
            • Then - Actions
              • Set VariableSet TempPoint = ((Center of (Playable map area)) offset by 256.00 towards ((Real((Integer A))) x 45.00) degrees.)
              • Unit - Create 1 PICK for (Player((Integer A))) at TempPoint facing Default building facing degrees
              • Set VariableSet PickerUnit[(Integer A)] = (Last created unit)
              • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions
      • Game - Display to (All players) the text: |cffffc832You have ...
      • Wait 20.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (PickingCheckForAll <gen> is on) Equal to True
        • Then - Actions
          • Player Group - Pick every player in Players and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • PlayerPickedStatus[(Player number of (Picked player))] Equal to False
                • Then - Actions
                  • Set VariableSet TempPlayer = (Picked player)
                  • Trigger - Run PickingDetermineRandom <gen> (checking conditions)
                • Else - Actions
        • Else - Actions
Would love to know if anyone has any clue if I am making some mistake or if there is a bug that I am not aware of.
 
Last edited:
Level 3
Joined
Nov 13, 2010
Messages
6
It reliably worked. Previously I was creating different units at different stage.
  • VariableInitialize
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Display Message --------
      • Game - Display to (All players) for 15.00 seconds the text: |cffc80000Player Re...
      • -------- Zombie Spawn Regions --------
      • Set VariableSet SpawnRegion[0] = Region 002 <gen>
      • Set VariableSet SpawnRegion[1] = Region 003 <gen>
      • Set VariableSet SpawnRegion[2] = Region 004 <gen>
      • Set VariableSet SpawnRegion[3] = Region 005 <gen>
      • -------- Hashtables --------
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableHouse = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableMine = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtablePlayerProp = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableGeneral = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableTerrain = (Last created hashtable)
      • -------- Remove structures --------
      • Unit Group - Pick every unit in (Units owned by Player 10 (Light Blue).) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • -------- Player Setup --------
      • Set VariableSet TempInt = 1
      • Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Game - Display to (All players) for 10.00 seconds the text: ((Name of (Picked player)) + has joined the game.)
              • Player Group - Add (Picked player) to Players
              • Player - Limit training of Heroes to 1 for (Picked player)
              • Hashtable - Save 0 as 200 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Hashtable - Save 0.00 as 201 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Hashtable - Save 0 as 205 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Player - Make (Picked player) treat Player 10 (Light Blue) as an Ally with shared vision
              • Set VariableSet PlayerNumber[(Player number of (Picked player))] = TempInt
              • Set VariableSet TempInt = (TempInt + 1)
              • Set VariableSet PlayerIcon[(Player number of (Picked player))] = ReplaceableTextures\CommandButtons\BTNAvatarOff.blp
              • -------- Setup Player Colors --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 1 (Red)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FF0000
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 2 (Blue)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c000000FF
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 3 (Teal)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c0040E0D0
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 4 (Purple)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00A020F0
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 5 (Yellow)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFFF00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 6 (Orange)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFA500
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 7 (Green)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c0000FF00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 8 (Pink)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFC0CB
                • Else - Actions
            • Else - Actions

  • VariableInitialize Copy
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Display Message --------
      • Game - Display to (All players) for 15.00 seconds the text: |cffc80000Player Re...
      • -------- Zombie Spawn Regions --------
      • Set VariableSet SpawnRegion[0] = Region 002 <gen>
      • Set VariableSet SpawnRegion[1] = Region 003 <gen>
      • Set VariableSet SpawnRegion[2] = Region 004 <gen>
      • Set VariableSet SpawnRegion[3] = Region 005 <gen>
      • -------- Hashtables --------
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableHouse = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableMine = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtablePlayerProp = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableGeneral = (Last created hashtable)
      • Hashtable - Create a hashtable
      • Set VariableSet HashtableTerrain = (Last created hashtable)
      • -------- Remove structures --------
      • Unit Group - Pick every unit in (Units owned by Player 10 (Light Blue).) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • -------- Player Setup --------
      • Set VariableSet TempInt = 1
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
              • Game - Display to (All players) for 10.00 seconds the text: ((Name of (Picked player)) + has joined the game.)
              • Player Group - Add (Picked player) to Players
              • Player - Limit training of Heroes to 1 for (Picked player)
              • Hashtable - Save 0 as 200 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Hashtable - Save 0.00 as 201 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Hashtable - Save 0 as 205 of (Player number of (Picked player)) in HashtablePlayerProp.
              • Player - Make (Picked player) treat Player 10 (Light Blue) as an Ally with shared vision
              • Set VariableSet PlayerNumber[(Player number of (Picked player))] = TempInt
              • Set VariableSet TempInt = (TempInt + 1)
              • Set VariableSet PlayerIcon[(Player number of (Picked player))] = ReplaceableTextures\CommandButtons\BTNAvatarOff.blp
              • -------- Setup Player Colors --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 1 (Red)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FF0000
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 2 (Blue)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c000000FF
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 3 (Teal)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c0040E0D0
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 4 (Purple)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00A020F0
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 5 (Yellow)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFFF00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 6 (Orange)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFA500
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 7 (Green)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c0000FF00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Picked player) Equal to Player 8 (Pink)
                • Then - Actions
                  • Set VariableSet MultiBoardPlayerColor[(Player number of (Picked player))] = |c00FFC0CB
                • Else - Actions
            • Else - Actions
I do think I may have found the ISSUE. Not 100% sure as I am still trying to test it. My main concern when i was creating units with offset originally :
  • Set VariableSet TempPoint = ((Center of (Playable map area)) offset by 256.00 towards ((Real(PlayerNumber[(Player number of (Picked player))])) x (360.00 / (Real((Number of players in Players))))) degrees.)
It would constantly fail at it and once i replaced it with :
  • Set VariableSet TempPoint = ((Center of (Playable map area)) offset by 256.00 towards ((Real(PlayerNumber[(Player number of (Picked player))])) x 45.00) degrees.)
It seems to work. Need to get a multiplayer tests going to confirm.
 
Level 3
Joined
Nov 13, 2010
Messages
6
I must apologies for the trouble. I think I have finally realized what was causing issues for me and why.

I must note that my original post did not include the original problem as I was trying to fix it thus simplifying it.
  1. Trying to distribute units according to player group size was causing the first issue. I am not knowledgeable enough with world editor but if I had to guess calling to get Players - Count players in player group messes with loop for all players.
    • Player Group - Pick every player in Players and do (Actions)
      • Loop - Actions
        • Set VariableSet TempInt = (Number of players in Players)
    This will cause to only loop once
  2. This next one seemed to cause odd issues for me but that may have just been due to me introducing errors when trying to fix it. Calling loop for player group inside a loop for player group will break it.
    This was the original issue I had but it looked like it was in a different place than I originally though.
    • PickingCreateTaven
      • Events
      • Conditions
      • Actions
        • Player Group - Pick every player in Players and do (Actions)
          • Loop - Actions
            • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from (Center of (Playable map area)) to a radius of 512.00.
        • Unit - Create 1 Portal for Neutral Passive at (Center of (Playable map area)) facing Default building facing degrees
        • Player Group - Pick every player in Players and do (Actions)
          • Loop - Actions
            • Camera - Pan camera for (Picked player) to (Center of (Playable map area)) over 0.00 seconds
            • Selection - Select (Last created unit) for (Picked player)
        • -------- THE SHIT IS BROKEN --------
        • Player Group - Pick every player in Players and do (Actions)
          • Loop - Actions
            • Unit - Create 1 PICK for (Picked player) at (Center of (Playable map area)) facing Default building facing degrees
            • Set VariableSet PickerUnit[(Player number of (Picked player))] = (Last created unit)
        • Game - Display to (All players) the text: |cffffc832You have ...
        • Wait 20.00 seconds
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (PickingCheckForAll <gen> is on) Equal to True
          • Then - Actions
            • Player Group - Pick every player in Players and do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • PlayerPickedStatus[(Player number of (Picked player))] Equal to False
                  • Then - Actions
                    • Set VariableSet TempPlayer = (Picked player)
                    • Trigger - Run PickingDetermineRandom <gen> (checking conditions)
                  • Else - Actions
          • Else - Actions
    The issue was not under -------- THE SHIT IS BROKEN -------- even though that appeared to be the first instance of it breaking. But rather in the final Player group Loop that was calling Trigger - Run PickingDetermineRandom... Although it did not contain Player Group loop another function that it called did and I was unable to find it until I tested every part of the trigger.
    • PickingCheckForAll
      • Events
      • Conditions
      • Actions
        • -------- Check if everyone has picked --------
        • Set VariableSet TempBool = True
        • Player Group - Pick every player in Players and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • PlayerPickedStatus[(Player number of (Picked player))] Equal to False
              • Then - Actions
                • Set VariableSet TempBool = False
              • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TempBool Equal to True
          • Then - Actions
            • Trigger - Run PickingComplete <gen> (checking conditions)
            • Trigger - Turn off (This trigger)
          • Else - Actions
    That was the final part where I ended up running another for Player Group Loop.
    • Sowcase
      • Events
      • Conditions
      • Actions
        • Player Group - Pick every player in Players and do (Actions)
          • Loop - Actions
            • Player Group - Pick every player in Players and do (Actions)
              • Loop - Actions
                • Do something

Sorry for the trouble again. Ill see to change this to Solved even though it was mostly caused by my own ineptitude.
  • PickingCreateTaven
    • Events
    • Conditions
    • Actions
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from (Center of (Playable map area)) to a radius of 512.00.
      • Unit - Create 1 Portal for Neutral Passive at (Center of (Playable map area)) facing Default building facing degrees
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Camera - Pan camera for (Picked player) to (Center of (Playable map area)) over 0.00 seconds
          • Selection - Select (Last created unit) for (Picked player)
      • Set VariableSet TempInt = (Number of players in Players)
      • Player Group - Pick every player in Players and do (Actions)
        • Loop - Actions
          • Set VariableSet TempPoint = ((Center of (Playable map area)) offset by 256.00 towards ((Real(PlayerNumber[(Player number of (Picked player))])) x (360.00 / (Real(TempInt)))) degrees.)
          • Unit - Create 1 PICK for (Picked player) at TempPoint facing Default building facing degrees
          • Set VariableSet PickerUnit[(Player number of (Picked player))] = (Last created unit)
          • Custom script: call RemoveLocation(udg_TempPoint)
      • Game - Display to (All players) the text: |cffffc832You have ...
      • Wait 20.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (PickingCheckForAll <gen> is on) Equal to True
        • Then - Actions
          • Game - Display to (All players) for 10.00 seconds the text: Randomise remaining
          • For each (Integer A) from 1 to 8, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • PlayerPickedStatus[(Integer A)] Equal to False
                • Then - Actions
                  • Set VariableSet TempPlayer = (Player((Integer A)))
                  • Trigger - Run PickingDetermineRandom <gen> (checking conditions)
                • Else - Actions
        • Else - Actions
 
Level 2
Joined
Feb 14, 2020
Messages
19
I am glad you fixed the issue. Though I never understood what the problem was. If you wanna loop multiple times then put the loop inside another loop.
 
Level 2
Joined
Feb 14, 2020
Messages
19
Nesting works fine for me

  • Actions
    • Set VariableSet activePlayers = (All players matching (((Matching player) slot status) Equal to Is playing).)
    • Player Group - Pick every player in activePlayers and do (Actions)
      • Loop - Actions
        • Game - Display to (All players) the text: (Name of (Picked player))
    • Wait 2.00 seconds
    • Player Group - Pick every player in activePlayers and do (Actions)
      • Loop - Actions
        • Player Group - Pick every player in activePlayers and do (Actions)
          • Loop - Actions
            • Game - Display to (All players) the text: (Name of (Picked player))
        • Game - Display to (All players) the text: Outer loop
    • Wait 2.00 seconds
    • Player Group - Pick every player in activePlayers and do (Actions)
      • Loop - Actions
        • For each (Integer A) from 1 to 10, do (Actions)
          • Loop - Actions
            • Game - Display to (All players) the text: (Name of (Picked player))
            • Game - Display to (All players) the text: (String((Integer A)))
        • Game - Display to (All players) the text: Outer loop
    • Wait 2.00 seconds
    • For each (Integer A) from 1 to 10, do (Actions)
      • Loop - Actions
        • Player Group - Pick every player in activePlayers and do (Actions)
          • Loop - Actions
            • Game - Display to (All players) the text: (Name of (Picked player))
            • Game - Display to (All players) the text: (String((Integer A)))
        • Game - Display to (All players) the text: Outer loop
 

Attachments

  • nestedTest.w3m
    17.1 KB · Views: 25
Level 3
Joined
Nov 13, 2010
Messages
6
Doesn't seem to do for me tho. At this rate I feel like I'm left with more questions than answers.
  • Nested Player Loop
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players controlled by a Computer player) and do (Actions)
        • Loop - Actions
          • Player Group - Add (Picked player) to All_Players
      • Game - Display to (All players) the text: (Players in group : + (String((Number of players in All_Players))))
      • Player Group - Pick every player in All_Players and do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (Pre Player + ((String((Player number of (Picked player)))) + loop))
          • Player Group - Pick every player in All_Players and do (Actions)
            • Loop - Actions
              • Game - Display to (All players) the text: (Inner player + (String((Player number of (Picked player)))))
          • Game - Display to (All players) the text: (Post Player + ((String((Player number of (Picked player)))) + loop))
Here is the output of what I got. Capture.PNG


I feel its best to leave this abomination as is before it drives anyone insane.
 

Attachments

  • PlayerGroupLoops.w3x
    17.7 KB · Views: 25
Level 2
Joined
Feb 14, 2020
Messages
19
I am sorry, I forgot fundamentals. The issue is youre using the same variable in both loops.

By the time your inner loop is finished, the outer loop will have its variable set to the.. end? And thus the outer loop is exited immediatly. My english is bad, I hope you understand.
I think you understand it better if you use integer loops. If you want to nest you cannot use 2 integer A loops but must use one A loop and one B loop.
 
Status
Not open for further replies.
Top