That naming convention could be quite handy, I however group things the way they are used, for instance dialog1_button dialog1_art dialog1_text, this works especially well in combination with Records. I am probably going to write up another section naming conventions, as they are especially personal, and there is not really any one convention better than the other, just personal preference.
I am going to rewrite the loop section to mainly cover the differences between while and for loops.
(There are always exceptions, when in doubt use common sense.)
As I said in the first paragraph, these are just a set of rules that I follow, perhaps I should expand on it, something along the lines of "These are just guidelines that I believe will help you improve your general scripting ability"?.
This is just a first draft, and is of course open to debate as I encouraged, which is why I explained that it was for developing good habits, nothing more. Will having a map full of global variables instead of records slow it down? Nope. Will having a map full of For loops rather than While loops 'noticably' slow it down? Probably not, and will a map which has a few hundred triggers compared to using functions slow it down? Well actually yes. So two out of the three are subjective, this is not a thread saying omg, you must do what I say or else, but as mentioned before, teaching people to improve their scripting.
Nearly everything I script is dynamic, ie, using variables, I have not noticed any performance issues over using direct numbers - because of the reason you mentioned, for better maintainability. I wish to expand upon that in more detail but thought a seperate thread would be suffice.
As I said before, it is for better habit forming. Whilst it has been established that For Loops have been 'fixed', if you start a career in programming by learning the basics scripting Starcraft II maps, it is better to be use to using While Loops rather than For Loops.
The difference between While and For is about 2-5 seconds of clicking, and a While loop gives you more control over the loop when you get into more advanced coding, where a For loop does not give you that control. Even though a For loop is technically just a While loop in galaxy, I believe it is better to educate the masses to do something correctly rather than easy, after all, if you are smart you would have a blank trigger where you would have all your mostly used functions (such as a while loop set up) that you can copy and paste into any script.
Perfect code is overrated, my code is not perfect. But what we want as a map making community is to raise the bar of people's creation, having good clean efficient code allows bugs to be spotted by other people (mentors) with greater ease. Your comment that "For Loops are faster to make and probably easier to maintain" really shows a lot about your knowledge, or lack there of. A few extra seconds setting up a loop is not going to add another months development time to your project, it is in this essense of laziness, that bad habits are formed and as a result, bad code exists.
"ALWAYS create local variables = parameters of the same name, do not use parameters in coding. Why? So you can copy and paste code obviously." and then "Copying and pasting code is bad."
Copying other people's code is bad, copying your own code is just plain common sense :P
It was merely directed at people who copy other peoples code and then never understand how it works, it is better to say have the code in a text format and write it yourself so you understand everything behind it. Like in shop class (woodwork), you don't grab someone else's wood duck and say it is yours, even if you have the measurements, you gotta cut it yourself.
Besides, I've always thought that copy/pasting code from other places and modifying it is a good way to learn. Sure it won't be optimal, but if it's a matter of doing something poorly or not doing it at all, I know what I'd choose. And once you've learnt enough you can edit the bad code. Opening the campaign maps can be a good idea when you want to do "that thing in that mission". It was very helpful for me to figure out how to make abilities with charges and pickups.
I did that as well when I first started scripting back in 2003, but I believe I learnt more through trial and error than I ever did reading other people's code. Do not confuse looking at Data (spells/abilities) and the Trigger Editor. Scripting is easy to pick up but extremely hard to master, and bad code is what breaks 90% of maps - you hardly ever see bad data breaking a well played map.
As for Records, I don't find them worth the effort. Player.deaths instead of player_deaths? Big deal. Sort your variables into folders if you have a lot of them and use a naming scheme and allows you to skip to a certain letter to find your variables.
I did that, but Tofu was sitting at over 800 global variables, Records take maybe 5 seconds to set up? If you set them up at the beginning of a project rather than say me, who spent a couple of painstaking days changing all global variables to records, and all for loops to while loops. My three rules of common sense in the trigger editor do not need to be used, they are merely guidelines to help people improve their scripting, and I personally believe Records are one of the best things Blizzard ever did for Sc2 compared to Wc3, along with native local variables in the GUI.
I personally like direct to the point threads, this is not some breastfed tutorial thread, this is for like-minded technical people who want to improve their GUI scripting skills, listing out a basic set of rules that I myself follow to keep my scripting smart and consistent.
No bullsh!t, just straight to the point radioactive baby formula for the masses.
The three basic rules of Scripting smartly (Using the GUI Trigger Editor).
DO - Use Functions.
DO - Use Records.
DO - Use While Loops instead of For Loops, and use loops whenever possible.
Otherwise this can be translated into ...
DO NOT - Create a map with 500 triggers.
DO NOT - Create a map with 800 global variables.
DO NOT - Use For Loops, especially while nested, ever.
If you did any of the three above, I sincerely suggest it is time for a re-write and to do things properly this time, the sooner you start the sooner you will finish and you do not want to wait until this get too complicated, you will thank me later.
Some Additional Things.
LABEL THINGS, have prefixes for things such as Action Definitions that will allow you to find them faster later.
LEARN ARITHMETIC, you know, the 1+2=3 stuff in primary school. For most people it is common knowledge but quite a few people expect to be able to script without any mathematic skills.
Algebra in a nutshell, x=1, y=2, z=? ... x+y=z, therefore Z must be 3. Ta da.
Use LOOPs whenever you can, you creating a dialog for each player? Do not create a dialog for each player, create one dialog for everyone to share, then update it using a loop.
(There are always exceptions, when in doubt use common sense.)
A variable can be anything, hence the name, you can change what it is at anytime. There are many many different types, but the two you will use most often as Boolean (True or False) and Integer (1,2,3 etc).
Players ARE Integers.
This means each player is given a unique number in the game, between 1 and 14. Neutral is 0, and Hostile is 15 (This is a total of 16 slots).
Always put variables into Records, do not create a huge list of Global Variables outside records.
Parameters are information you put in.
Return is the information you receive back.
ALWAYS create local variables = parameters of the same name, do not use parameters in coding. Why? So you can copy and paste code obviously.
There are two types of functions that I will quickly touch on, Functions return a value, Action Definitions do not, they are simply a trigger without an event.
Below is a simple function that I would like you to recreate, it does not need any global variables.
NameOfPlayerinColourOptions:FunctionReturnType:TextParametersplayer=0<Integer>GrammarText:NameOfPlayerinColour(player)HintText:(None)CustomScriptCodeLocalVariablesplayer=player<Integer>text=NoText<Text>ActionsVariable-Settext=(Combine("<c val="", (Text((Convert color (Color((Current player player color))) to string))), "">",(Nameofplayerplayer),"</c>"))General-Returntext
Creating the Function shown above
Right click on the trigger list, create new function, name it "Name of Player in Colour".
Change the return type to text.
Create a parameter called player, of an integer type.
Create two variables, one called player set to the parameter player, the other called text of text type.
Then set Text as Text Combine Multiple (you will need five combines).
Convert String to Text ( Convert Colour to String ( Convert Player Colour to Colour ( ( player variable ) - current colour ) ) )
Name of Player ( player variable )
Then Return text
To see this function in action, you should create a new Action - Text Message and then go down to Name of Player in Colour (not Name of Player) and set the player as 1. It should show your name in your colour when you test the map, make sure the text message is set to Chat Area.
So instead of you having to waste time every time you want to show a player's name in their colour having to create a text multiple, then <c val, then colour etc etc, you can just use this one function. Every technical thing you do more than once should be in a function to save you time!
Action Definitions are basically a trigger without an event, use these for everything, think of them like Folders but only for triggers. For instance, my Map Initialization in Tofu has one line.
You will see I label them different codes for what they do, in this case ti_ stands for Tofu Initialization, this is common sense, it makes finding them very fast.
For trouble shooting this also allows you to turn off things one at a time to see what is going wrong.
Action Definitions can also use Parameters, so you can create an Action Definition that updates a dialog for a specific player.
People explained to me that records are like a folder you put variables in, but no one every told me how to create one. Stupid in hindsight? Correct.
In Wc3 I labelled variables like player_kills(15) player_deaths(15) etc. But when you reach over a couple of hundred variables, in my case 800, then finding them becomes quite slow. Records allow you to streamline this process and keep everything neat and tidy.
Creating a Record
Right click in the trigger pane and click Create new Record, name it Player Data.
Straight under that Right Click in the trigger pane and click Create new Variable, name it Player and set the type to - Record (Player Data), make it an array set to 15.
Wow that was easy wasn't it? Damn everyone who never told me you needed to create a variable to use a record. At least I am telling you, feel special? <3
Now create two variables inside the Player Data Record, named kills and deaths of type integer.
Now go outside to any trigger and do Set Variable, there you will see it has the record called Player, click that then set the Player to 1, and then kills.
So instead of having variables such as:
You have a nice little record that moves the  to after the player and before whatever it is.
You can put records inside records, but they must be above the master record which stores the variables of type record, for instance.
Remember, the "master" record must always be BELOW the ones you want to put inside it.
While Loops, Never ever use For Loops
Using while loops rather than for loops dramatically decreases your script size, decreases the overload and increases map performance. 9 out of the top 10 mappers agree that you should never ever use for loops, the other one is a noob, you don't want to be a noob do you?
X is the loop, Y is the starting value, and Z is the cut off value.
Alright, so For Loops basically give you;
For Each Integer (x) from (y) to (z) do blah.
While loops take a few seconds longer to set up. You need three lines to set up a While Loop. I will use the same variable names (x,y,z) below as I did above so you can see where it fits in.
Understand? The amounts, x,y,z are still there! Just in a different format.
So you need to set the loop variable X before the while loop to the starting amount. The IF condition is the cut off amount, in this case while X is less than or equal to Z do blah, and then at the very end of the while loop you need a Modify X + 1.
While loops are also handy as you can do a very simple timer on them, and have an extra condition say playersready=false, that when set to true will finish the timer.
This one counts down because the modify is now negative. There are a few different schools of thought about using wait timers, I do not personally see the harm in them, and think in moderation, say used at the beginning of the game to countdown a selection dialog box is fine.
Limit your Triggers
The only time you need a trigger is when you need an event to fire one. You should not have multiple triggers for each player, instead use one trigger for everyone and either use Triggering Player or a loop to get the information you need. The more triggers you have firing the more overhead you create and the sooner you will hit that limit. Tofu will perhaps become one of the most polished maps ever seen, but I believe most people will be shocked at how simply and efficient it is written, with next to no triggers, and the payload mainly consisting of functions.
I have seen some maps (ie Phantom Mode) have 14 triggers to allow people to write a command such as -players. You only need one trigger, with multiple events, that uses trigger playing to get the player. This whilst not effecting the game so much, is bad practice in keeping clean code.
Also using Action Definitions allows you to Create Threads when needed, especially with loops, to reduce the overhead of the running script.
Copying and pasting code is bad. Reading someone else's code out of a map that has been unprotected is bad. Not purely because because of ethical reasons, but because chances are they have really badly written code. You will be amazed at how badly written most of the top 20 maps are, and whilst you do not need perfect coding to create a successful map, you should want your map to 'be all that it can be'.
Open Source vs Unprotecting
Whilst I do not want Tofu open sourced, I know that without a doubt that it will be available unprotected, and whilst I do not really have a problem with that because that it will only be available in Galaxy, and people will not be able to easily edit it in GUI until there is a parser available, there is nothing that I have done that you cannot do with some time. I am not hiding secrets, I have no problem with sharing my knowledge to those willing to learn, but if you are even so lazy as to not write your own code from an example given above, and would rather copy and paste it into your map, then it doesn't matter :) Cause your map will only ever be as good as your ability, and you are shooting yourself in the ass, nananana ... <3
Read it all.
Suggestions / Agreements / Disagreements
Spam me below and I will update this post if appliciable.