Okay, so SoulCarverr, I've been converting my While loops to For loops. Then I make a new one, create an awesome dialog, but everything my If statement inside the loop is screwing up. The For is For Each Integer in ColumnTotal from 1 to 3. the IF is ColumnID < Column Total. This failed over and over again, and I tried 10 ways to find out. Once I swapped the comparison to ColumnID < 3 it worked perfectly. But I needed to use the ColumnTotal variable to let my dialog flex.
Pull the original code out and stick it in a while loop and it works perfectly. Why do you think the for loop is so good when it fucks up your variable?
EDIT: I just used the integer to text func to display a message with the ColumnID variable in that For loop. It gave me 4 5 6, not 1 2 3. Anyone know wtf is with that?
EDIT2: the 4 5 6 is unrelated, I fixed that. Issue still persists.
I'd be happy to try help but have trouble imagining problems from descriptions (I'm more of a visual guy). Would you kindly post a snippet of your code?
Tad bit of extra info: For loops in GUI are actually compiled into while loops in galaxy when you save your map. Proof of this is that you can build a simple for loop in an empty map, save it, then press Ctrl + F11 to view the compiled script, and expect to find a while loop representing that particular for loop.
The above is the generated script for a GUI for loop that iterates from 0 to 5, as can be seen, it has been converted into a very poorly done while loop.
I'd still give him credit for his efforts, as he offered his help with good intent. I read his earlier post on for loops and I do agree to a certain extent with it, in particular that for loops are more controlled.
I would have worded it differently though; For loops (in most languages) are bounded in that a lower/upper/increment are prerequisites for it to work. Compiler would probably spit out syntax error messages if any of them were missing. This reduces the chance of accidentally making an infinite loop and crashing the game engine. I don't think it prevents it though, it could still break if 0 was set as the incremental value (in theory it should be possible).
Have you thought about player groups for this task?
UntitledTrigger001Events------- Deisgned for only two teams.Timer-Elapsedtimeis0.1GameTimesecondsLocalVariablesGroup.Team1=(Emptyplayergroup)<PlayerGroup>Group.Team2=(Emptyplayergroup)<PlayerGroup>WhichTeamToAssignTo=False<Boolean>ConditionsActionsPlayerGroup-Pickeachplayerin(ActivePlayers)anddo(Actions)ActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfWhichTeamToAssignTo==TrueThenPlayerGroup-Addplayer(Pickedplayer)toGroup.Team1Variable-SetWhichTeamToAssignTo=FalseElsePlayerGroup-Addplayer(Pickedplayer)toGroup.Team2Variable-SetWhichTeamToAssignTo=TruePlayer-MakeallplayersinGroup.Team1treateachotherasAllyWithSharedVisionPlayer-MakeallplayersinGroup.Team2treateachotherasAllyWithSharedVision
I created a new map, copied the code, and reset it up. It produces 1-2-3. I have no idea what's going on. Using this same code in a While loop in the GUI produces the desired result, and using the For loop in a new map produces the desired result. So confusing.
@Zandose, I'll definitely be setting player groups in the lobby, this was just about learning to code. Thanks for pitching in!
About For vs While: I realized why he thought for loops gave you more control. They are more "controlled", like you said, not that they give you more control. I have to agree, but now I'm really iffy about for loops with this new issue.
By the way guys, I'm having so much fun coding my interface! Everytime something works I feel like Einstein or something.
EDIT:
Found out why it was producing 4-5-6, I had it after my while loop that was modding the vaible +1 each time it ran. But I didn't create that While loop till after the for loop wasn't working, so I have no idea what went wrong still.
The first tutorial I learned from regularly used If Then Else statements, but never put anything in Else. Is there a better way to add a condition to an action?
Yeap, thats the script I'm looking for. Very wierd bug you're facing. Not clear from the snippet why it's not working. If it's not too much trouble, Could you post the script for the entire trigger that's not working properly? Including variable initializations and stuff. We should be expecting the script to be within a trigger block that looks something like the following:
Edit: The random trigger name will probably be some crappy alphanumeric
Edit2: Reading over your earlier post. Not very clear about how the script is failing.
What is the script supposed to do?
What is the actual result?
Edit3:
Based on the snippet above and assuming the following initializations:
columnID = 0
columnTotal = 0
auto38486ABD_ai (Increment) = 1
auto38486ABD_ae (Final) = 5
The result of the if condition and the variable values at the end of each iteration:
Condition, columnTotal, columnID
False, 0, 0
False, 1, 1
False, 2, 2
False, 3, 3
False, 4, 4
False, 5, 5
Both columnTotal and columnId appear to be incrementing (columnId is incrementing in both the if and else blocks), so the condition never evaluates to true. Could this be causing the problem?
Yeah, I'd have to recreate the trigger, and since the while loop is working just fine I deleted it.
But I can tell you what the script is supposed to do. I'm creating a dialog with contents arranged in 3 columns. Content is assigned its X offset by a variable (called AccumulativeX). Once the three columns of content is created, AccumulativeX is used to determine the total dialog width, so the dialog resizes according to the content within.
The loop has 3 passes to create the 3 columns of content. On pass 1 and 2, after all the content is created, it adds the column width to AccumulativeX, so that the content in the next pass is offset correctly. But on the 3rd pass, if a whole column's width is added to AccumulativeX, you end up with a dialog box 4 columns wide, but with only 3 columns of content.
So, each pass modifies ColumnID +1. An IF statement is created. If ColumnID<TotalColumns (aka 3), Then add 1 column width to AccumulativeX. Else, it just adds a bit to AccumulativeX so the boarder doesn't crowd the content.
My issue is that, while this was a For loop, the trigger always performed the "then" actions, unless I set it to be If ColumnID<3. I wanted to be able to change the amount of columns by changing one variable, TotalColumns, though. Something about having the For loop (For each Integer in TotalColumns from 1 to TotalColumns with increment of 1) made ColumnID<TotalColumns never return false. Changing nothing and switching to a while loop fixed the issue.
Changing nothing and switching to a while loop fixed the issue.
Mmm.. Really not sure why the for loop wasn't working :/ Is there any problem with just using the while loop? I honestly don't see a reason not to since it works.
Yes and no. While loops, if not properly made or the unexpected happens, can run on forever crashing the game. So I don't use them often. If it works for you it works. I believe FoxyMayhem said there was a chance of their being a fourth column, so it's uncertain if he'd need the for-lopp to run 3 or 4 times. and therefore a while-loop wouldn't probably be a good option as long as safety's were added.
As for the for-loop not working, you probably missed something as for-loops can do anything while-loops can, you just need to change the code a bit. You just need to debug it to hell.
@Fuzzy: No, there is no need for it to be a For loop. Thanks for looking, though, because if we DID figure out what was going on I could prevent it in the future.
@Zandose: the while loop is working well, I'm not sure what you mean in the last sentence of your first paragraph.
Er, what do you mean where is it at? I've been working on the concept for the game for about a year. Now I'm learning the skills needed to make it in SC2.
The pie-in-the-sky idea is that SC2 reduces development overhead by allowing me to use their art and engine. I can create the game and test it, a sort of proof of concept for the design ideas behind it. If things pan out, or I/we can develop a better design formula that is "easy to pick up, hard to master" and delivers a better spectator sport experience than SC2, Dota, or League, then I might actually develop the game for realzies.
Like I said, pie in the sky. But thanks to SC2 I can prototype the idea for cheap.
If you're curious, here's a decent article I wrote on esports design: Designing an Esport, p1
Help me understand the for loop a bit more. It says "For each [player] in [player group]", what is that first variable for? I just want every player in the selected player group.
Same thing with For each [Integer] from [1] to [10] with increments of [1]. What is that first variable for?
For Each is a little self explanatory, it simply means for each and every element in a group. So if you got an array of 20 ints, it will do all 20, array of 30 ints, it will do all 30. In your case, it will do this for each player inside the group. Just be sure you don't confuse this with a for loop. I'm not sure what the SC2 syntax is, but basically lets say have an int array with 20 ints called numbers you wanted to print out that counted from 1 to 20.(for this example the array is already populated)
Keep in mind this is PSEUDO CODE, meaning it won't compile, it is just for logic sake.
int i = 0;
//For Loop Example
//int i = 0 is just defining an int variable, i < 10 is the condition it
//checks to see if it goes again, ++i simply pre-increments i by 1
for(int i = 0; i < 10; ++i)
{
UIDisplayMessage(IntToText(numbers[i]),playergroup(all));
}
//This would display:
0
1
2
3
4
5
6
7
8
9
10
for each integer in numbers
{
UIDisplayMessage(IntToText(i),playergroup(all));
}
//This would display:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Please try not to get too hung up on the details, just understand for now, a for each loop grabs everything out of a group/array whatever, and a for loop goes a set number of times based on the conditional expression you compare it against.
Have you studied java or c at all? I would recommend you start from the beginning if not, might help you out a lot to get comfortable with variables/if statements before you delve too deep into this kind of thinking, it makes a lot more sense with that kind of background.
I feel like I have variables and if statements down, I'm making some very complex stuff with those and its all working. I just don't understand what the For Each Player in Player group is asking me for with its first variable.
Maybe I can tell you my need, and you'll tell me how to use For Each Player in Player group (or whatever solution you have) to meet that need.
I need the loop to run as many times as there are players in the player group Team 1. Simple as that. So I make a "For each [ ] in [Players on team 1] do actions:". What do I put in that first variable field?
The only thing I can think of is to create a function that counts the number of players in Team 1 and then sets a variable to = the number of players, then use that variable. But then the language makes no damn sense (For each [3] in [Players on team 1] do actions).
What the actual fuck does that mean? The only thing that variable field will accept are variables and parameters (and custom script). I can't even set a hardcoded value if I wanted.
That's the most perplexing part, if you just pretend for a moment that [player] is not a field, it makes sense: "For each player in [Players on team 1] do actions". That makes sense. But it wants me to change "player" to something so that it says stuff like "For each [3] in [Players on team 1] do actions", and that makes no sense. Just so you know, 3 = a variable that = 3, I can't actually tell it to just be 3. That's what I mean when I say I can't even set a hardcoded value if I wanted.
This is the GUI of it, what I'm not understanding:
I guess the wording can be a bit confusing. The variable will simply hold which player the loop is currently running for, it's just letting you pick which variable you want to use instead of doing it itself. Make a local integer variable and use that for the "player variable".
Also its just like the trigger under it called "Pick each player in (player group) and do actions", except in this case the trigger itself will provide the variable. So instead of using a local variable for the player you'd use the function "picked player".
I want to perform the action as many times as there is players on a team, but display the results to all. I don't use "picked player" for that, since I'm never referencing the player, just using the total players on a team as a value for how many times the loop runs.
And there are 3 players on team 1, it will create 3 images (ignoring the fact that the offset would stack the images on top of themselves) in the dialog box. And if that box is made visible for all players, then all players will see those 3 images.
Right?
Also, can you provide an example why I would want to specify my own variable? What is that actually useful for compared to "pick each player"?
Others have covered the WHAT... As for the WHY would you have 2 commands to do the same thing?
In effect, using the "pick each player" is like a shortcut where it will create a "hidden" variable which you can access using "picked player". Feel free to use this whenever you loop through a player group.
So why would you use the "worse" version? Well, there are times though when you would want to do things "by hand" so to speak, because you need more control than the "pick each player" is able to give you.
This is the first scenario that I thought of. Hopefully even if it is a bit more advanced than you are ready for you will be able to see why "picked each player" is too blunt a tool to use in complex situations.
EXAMPLE A -
You created an 8 player FFA game.
Once every minute you want to create 7 monsters belonging to player 1 at player 1s base and send them to attack each opponent.
You could create 7 commands:
this_player = 1;
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 2);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 3);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 4);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 4);
etcetc...
But the above solution is tedious, error prone, time consuming etcetc.
(EDIT: I just realised that I ACTUALLY made a mistake above which just goes to show how easy it is to do. I'm leaving the mistake in.)
Since we are only doing a simple loop we can use a "pick each player" loop. The code would be:
this_player = 1;
pick each player in group (all players)
{
if (picked player) != this_player
create a monster belonging to (this_player) in (this_player) base and send it to attack (picked player);
}
This will not do anything when "picked player" == this_player. Because it makes no sense to create a monster to attack our own base.
EXAMPLE B -
*surprise!* During play testing it was discovered that the game in example A completely sucks!
It was completely unfair to only create monsters to help player 1. But you liked the game mechanic so you decided to make it fair and do this for all players!
You could do this by creating 8 identical loops one for each player... or you could have a loop within a loop.
for each player (this_player) in group (all_players)
{
pick each player in group (all players)
{
if (picked player) != this_player
create a monster belonging to (this_player) in (this_player) base and send it to attack (picked player);
}
}
Notice that the inside loop is identical to the one in example A. (I LITERALLY copy&pasted it). The only thing I changed was to create a loop which iterates over the variable "this_player".
The reason that you HAD to use the "for each player" loop and NOT the "pick each player loop" was because you cannot have a "pick each player" within another "pick each player". this is because "picked player" usually refers to the player we are looping over, however if we are using 2 loops AT THE SAME TIME then there is no way to distinguish which player we meant... it could be the player from either loop! That is why we need the ability to specify a variable instead of letting "pick each player" do it for us.
CONCLUSION:
"pick each player" is more limited. It could be removed from the editor and I for one would not mourn its passing. However it is a bit like the "for" vs "while" arguments at the start of this thread. There is nothing wrong with using a less powerful tool to do a job. In fact, it is actively encouraged in most circumstances... It is not a good idea to use a steamroller to iron your clothes or a bulldozer to dig up weeds. Yes it is more powerfull, but there is a far greater chance of you f**king something up! "Less is more" and all that jazz.
tldr;
having a "pick each player" loop inside a "pick each player" loop makes no sense
Okay, so SoulCarverr, I've been converting my While loops to For loops. Then I make a new one, create an awesome dialog, but everything my If statement inside the loop is screwing up. The For is For Each Integer in ColumnTotal from 1 to 3. the IF is ColumnID < Column Total. This failed over and over again, and I tried 10 ways to find out. Once I swapped the comparison to ColumnID < 3 it worked perfectly. But I needed to use the ColumnTotal variable to let my dialog flex.
Pull the original code out and stick it in a while loop and it works perfectly. Why do you think the for loop is so good when it fucks up your variable?
EDIT: I just used the integer to text func to display a message with the ColumnID variable in that For loop. It gave me 4 5 6, not 1 2 3. Anyone know wtf is with that?
EDIT2: the 4 5 6 is unrelated, I fixed that. Issue still persists.
@FoxyMayhem: Go
I'd be happy to try help but have trouble imagining problems from descriptions (I'm more of a visual guy). Would you kindly post a snippet of your code?
Tad bit of extra info: For loops in GUI are actually compiled into while loops in galaxy when you save your map. Proof of this is that you can build a simple for loop in an empty map, save it, then press Ctrl + F11 to view the compiled script, and expect to find a while loop representing that particular for loop.
The above is the generated script for a GUI for loop that iterates from 0 to 5, as can be seen, it has been converted into a very poorly done while loop.
This is why you do not listen to SoulCarverr.
Edit: I forgot to read all the posts on page one lol. Deletes everything.
@DogmaiSEA: Go
I'd still give him credit for his efforts, as he offered his help with good intent. I read his earlier post on for loops and I do agree to a certain extent with it, in particular that for loops are more controlled.
I would have worded it differently though; For loops (in most languages) are bounded in that a lower/upper/increment are prerequisites for it to work. Compiler would probably spit out syntax error messages if any of them were missing. This reduces the chance of accidentally making an infinite loop and crashing the game engine. I don't think it prevents it though, it could still break if 0 was set as the incremental value (in theory it should be possible).
Have you thought about player groups for this task?
Okay, I used ctrlF11 and found the section that was giving me 4-5-6 when it should be giving 1-2-3. Is this what you wanted/
I created a new map, copied the code, and reset it up. It produces 1-2-3. I have no idea what's going on. Using this same code in a While loop in the GUI produces the desired result, and using the For loop in a new map produces the desired result. So confusing.
@Zandose, I'll definitely be setting player groups in the lobby, this was just about learning to code. Thanks for pitching in!
About For vs While: I realized why he thought for loops gave you more control. They are more "controlled", like you said, not that they give you more control. I have to agree, but now I'm really iffy about for loops with this new issue.
By the way guys, I'm having so much fun coding my interface! Everytime something works I feel like Einstein or something.
EDIT:
Found out why it was producing 4-5-6, I had it after my while loop that was modding the vaible +1 each time it ran. But I didn't create that While loop till after the for loop wasn't working, so I have no idea what went wrong still.
The first tutorial I learned from regularly used If Then Else statements, but never put anything in Else. Is there a better way to add a condition to an action?
@FoxyMayhem: Go
Yeap, thats the script I'm looking for. Very wierd bug you're facing. Not clear from the snippet why it's not working. If it's not too much trouble, Could you post the script for the entire trigger that's not working properly? Including variable initializations and stuff. We should be expecting the script to be within a trigger block that looks something like the following:
I'll see if I can spot the bug from there.
Edit: The random trigger name will probably be some crappy alphanumeric
Edit2: Reading over your earlier post. Not very clear about how the script is failing.
Edit3:
Based on the snippet above and assuming the following initializations:
The result of the if condition and the variable values at the end of each iteration:
Both columnTotal and columnId appear to be incrementing (columnId is incrementing in both the if and else blocks), so the condition never evaluates to true. Could this be causing the problem?
Yeah, I'd have to recreate the trigger, and since the while loop is working just fine I deleted it.
But I can tell you what the script is supposed to do. I'm creating a dialog with contents arranged in 3 columns. Content is assigned its X offset by a variable (called AccumulativeX). Once the three columns of content is created, AccumulativeX is used to determine the total dialog width, so the dialog resizes according to the content within.
The loop has 3 passes to create the 3 columns of content. On pass 1 and 2, after all the content is created, it adds the column width to AccumulativeX, so that the content in the next pass is offset correctly. But on the 3rd pass, if a whole column's width is added to AccumulativeX, you end up with a dialog box 4 columns wide, but with only 3 columns of content.
So, each pass modifies ColumnID +1. An IF statement is created. If ColumnID<TotalColumns (aka 3), Then add 1 column width to AccumulativeX. Else, it just adds a bit to AccumulativeX so the boarder doesn't crowd the content.
My issue is that, while this was a For loop, the trigger always performed the "then" actions, unless I set it to be If ColumnID<3. I wanted to be able to change the amount of columns by changing one variable, TotalColumns, though. Something about having the For loop (For each Integer in TotalColumns from 1 to TotalColumns with increment of 1) made ColumnID<TotalColumns never return false. Changing nothing and switching to a while loop fixed the issue.
Here is the functioning while code:
Changing nothing and switching to a while loop fixed the issue.
Mmm.. Really not sure why the for loop wasn't working :/ Is there any problem with just using the while loop? I honestly don't see a reason not to since it works.
PS: Sorry I couldn't help you with this one.
@FuzzYD: Go
Yes and no. While loops, if not properly made or the unexpected happens, can run on forever crashing the game. So I don't use them often. If it works for you it works. I believe FoxyMayhem said there was a chance of their being a fourth column, so it's uncertain if he'd need the for-lopp to run 3 or 4 times. and therefore a while-loop wouldn't probably be a good option as long as safety's were added.
As for the for-loop not working, you probably missed something as for-loops can do anything while-loops can, you just need to change the code a bit. You just need to debug it to hell.
So where is this project currently at?
@Fuzzy: No, there is no need for it to be a For loop. Thanks for looking, though, because if we DID figure out what was going on I could prevent it in the future.
@Zandose: the while loop is working well, I'm not sure what you mean in the last sentence of your first paragraph.
Er, what do you mean where is it at? I've been working on the concept for the game for about a year. Now I'm learning the skills needed to make it in SC2.
The pie-in-the-sky idea is that SC2 reduces development overhead by allowing me to use their art and engine. I can create the game and test it, a sort of proof of concept for the design ideas behind it. If things pan out, or I/we can develop a better design formula that is "easy to pick up, hard to master" and delivers a better spectator sport experience than SC2, Dota, or League, then I might actually develop the game for realzies.
Like I said, pie in the sky. But thanks to SC2 I can prototype the idea for cheap.
If you're curious, here's a decent article I wrote on esports design: Designing an Esport, p1
My bad. I was simply asking if you still wanted to convert your while-loop to a for-loop and where you were at with the code.
Help me understand the for loop a bit more. It says "For each [player] in [player group]", what is that first variable for? I just want every player in the selected player group.
Same thing with For each [Integer] from [1] to [10] with increments of [1]. What is that first variable for?
@FoxyMayhem: Go
For Each is a little self explanatory, it simply means for each and every element in a group. So if you got an array of 20 ints, it will do all 20, array of 30 ints, it will do all 30. In your case, it will do this for each player inside the group. Just be sure you don't confuse this with a for loop. I'm not sure what the SC2 syntax is, but basically lets say have an int array with 20 ints called numbers you wanted to print out that counted from 1 to 20.(for this example the array is already populated)
Keep in mind this is PSEUDO CODE, meaning it won't compile, it is just for logic sake.
Please try not to get too hung up on the details, just understand for now, a for each loop grabs everything out of a group/array whatever, and a for loop goes a set number of times based on the conditional expression you compare it against.
Have you studied java or c at all? I would recommend you start from the beginning if not, might help you out a lot to get comfortable with variables/if statements before you delve too deep into this kind of thinking, it makes a lot more sense with that kind of background.
I feel like I have variables and if statements down, I'm making some very complex stuff with those and its all working. I just don't understand what the For Each Player in Player group is asking me for with its first variable.
Maybe I can tell you my need, and you'll tell me how to use For Each Player in Player group (or whatever solution you have) to meet that need.
I need the loop to run as many times as there are players in the player group Team 1. Simple as that. So I make a "For each [ ] in [Players on team 1] do actions:". What do I put in that first variable field?
The only thing I can think of is to create a function that counts the number of players in Team 1 and then sets a variable to = the number of players, then use that variable. But then the language makes no damn sense (For each [3] in [Players on team 1] do actions).
What the actual fuck does that mean? The only thing that variable field will accept are variables and parameters (and custom script). I can't even set a hardcoded value if I wanted.
That's the most perplexing part, if you just pretend for a moment that [player] is not a field, it makes sense: "For each player in [Players on team 1] do actions". That makes sense. But it wants me to change "player" to something so that it says stuff like "For each [3] in [Players on team 1] do actions", and that makes no sense. Just so you know, 3 = a variable that = 3, I can't actually tell it to just be 3. That's what I mean when I say I can't even set a hardcoded value if I wanted.
This is the GUI of it, what I'm not understanding:
@FoxyMayhem: Go
I guess the wording can be a bit confusing. The variable will simply hold which player the loop is currently running for, it's just letting you pick which variable you want to use instead of doing it itself. Make a local integer variable and use that for the "player variable".
Also its just like the trigger under it called "Pick each player in (player group) and do actions", except in this case the trigger itself will provide the variable. So instead of using a local variable for the player you'd use the function "picked player".
Hm, okay, I understand that.
I want to perform the action as many times as there is players on a team, but display the results to all. I don't use "picked player" for that, since I'm never referencing the player, just using the total players on a team as a value for how many times the loop runs.
So just so I'm clear on this, if I use this:
And there are 3 players on team 1, it will create 3 images (ignoring the fact that the offset would stack the images on top of themselves) in the dialog box. And if that box is made visible for all players, then all players will see those 3 images.
Right?
Also, can you provide an example why I would want to specify my own variable? What is that actually useful for compared to "pick each player"?
Thanks, btw.
Others have covered the WHAT... As for the WHY would you have 2 commands to do the same thing?
In effect, using the "pick each player" is like a shortcut where it will create a "hidden" variable which you can access using "picked player". Feel free to use this whenever you loop through a player group.
So why would you use the "worse" version? Well, there are times though when you would want to do things "by hand" so to speak, because you need more control than the "pick each player" is able to give you.
This is the first scenario that I thought of. Hopefully even if it is a bit more advanced than you are ready for you will be able to see why "picked each player" is too blunt a tool to use in complex situations.
EXAMPLE A -
You created an 8 player FFA game.
Once every minute you want to create 7 monsters belonging to player 1 at player 1s base and send them to attack each opponent.
You could create 7 commands:
this_player = 1;
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 2);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 3);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 4);
create a monster belonging to (this_player) in (this_player) base and send it to attack (player 4);
etcetc...
But the above solution is tedious, error prone, time consuming etcetc.
(EDIT: I just realised that I ACTUALLY made a mistake above which just goes to show how easy it is to do. I'm leaving the mistake in.)
Since we are only doing a simple loop we can use a "pick each player" loop. The code would be:
this_player = 1;
pick each player in group (all players)
{
if (picked player) != this_player
create a monster belonging to (this_player) in (this_player) base and send it to attack (picked player);
}
This will not do anything when "picked player" == this_player. Because it makes no sense to create a monster to attack our own base.
EXAMPLE B -
*surprise!* During play testing it was discovered that the game in example A completely sucks!
It was completely unfair to only create monsters to help player 1. But you liked the game mechanic so you decided to make it fair and do this for all players!
You could do this by creating 8 identical loops one for each player... or you could have a loop within a loop.
for each player (this_player) in group (all_players)
{
pick each player in group (all players)
{
if (picked player) != this_player
create a monster belonging to (this_player) in (this_player) base and send it to attack (picked player);
}
}
Notice that the inside loop is identical to the one in example A. (I LITERALLY copy&pasted it). The only thing I changed was to create a loop which iterates over the variable "this_player".
The reason that you HAD to use the "for each player" loop and NOT the "pick each player loop" was because you cannot have a "pick each player" within another "pick each player". this is because "picked player" usually refers to the player we are looping over, however if we are using 2 loops AT THE SAME TIME then there is no way to distinguish which player we meant... it could be the player from either loop! That is why we need the ability to specify a variable instead of letting "pick each player" do it for us.
CONCLUSION:
"pick each player" is more limited. It could be removed from the editor and I for one would not mourn its passing. However it is a bit like the "for" vs "while" arguments at the start of this thread. There is nothing wrong with using a less powerful tool to do a job. In fact, it is actively encouraged in most circumstances... It is not a good idea to use a steamroller to iron your clothes or a bulldozer to dig up weeds. Yes it is more powerfull, but there is a far greater chance of you f**king something up! "Less is more" and all that jazz.
tldr;
having a "pick each player" loop inside a "pick each player" loop makes no sense