It really depends on what part of code you are currently working on. Even the old for loops were perfectly fine for about 95% of code at least, but for performance intensive code one should still prefer while loops and also always look at the generated galaxy output.
Still, the GUI to Galaxy "compiler" would really benefit from some additional intelligence, such as removing empty else {} clauses and automatically inserting the < or > check for for loops depending on the increment. It could also support inlining for very short functions and remove all not used variables, functions and triggers automatically.
exactly.
also i think perfect code is overrated. galaxy is kinda fast and its much more important that you understand your code and that its easy to work with it.
Clean code is paramount to everything else. If the kitchen is clean it is easy to spot the roaches, aka, bugs.
well, while loops might be a little bit faster, the question is
1) is it even noticeable? (no)
2) is it worth the additional work in gui?
everyone has to decide that for himself. for loops were just unusable bevore the fix since they totally f*cked up when nested.
if you look at a for loop in galaxy it looks like this:
the first three columns just set up the start, the end and the increment, what costs nearly zero performence.
then it continues with a while loop checking if the counter variable (i) is within bounds, if yes, it gets incremented and the actions are run. (if increment is < 0 it checks if its bigger the min, if its > 0 it checks if its smaller than max.)
if(lv_i==autoF4604CB0_ae){break;}
also costs nearly zero performance since its just a integer comparison.
so in fact the only performance loss you might encounter are 1-2 integer comparisons per loop execution, what should be not noticable in any way. but yes, for perfect code do while loops.
for me personally its exactly the other way around. in the past i used while loops only, now i start working with for loops since they are well usable imo, especially if you have nested loops its saves some time when working.
As for Records, I don't find them worth the effort. Player[15].deaths instead of player_deaths[15]? 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.
its very useful. think of creating a new map initially supporting max players (so each player array should have size 16), but later you decide to make it max 8 players. if you have a record storing all player variable arrays u just change the size of the record to 8. if you have the variables in a folder you have to change the size to 8 for EACH single variable, what would result in alot of work depending on how many variables you got, since you cant use constants to define array sizes in gui.
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?
for loops got fixed by blizzard a few versions back.
they are well usable now :)
but didnt know that either some weeks ago.
overall a nice guide that will be helpful for alot of beginners but also advanced mappers.
It really depends on what part of code you are currently working on. Even the old for loops were perfectly fine for about 95% of code at least, but for performance intensive code one should still prefer while loops and also always look at the generated galaxy output.
Still, the GUI to Galaxy "compiler" would really benefit from some additional intelligence, such as removing empty else {} clauses and automatically inserting the < or > check for for loops depending on the increment. It could also support inlining for very short functions and remove all not used variables, functions and triggers automatically.
@Kueken531: Go
exactly.
also i think perfect code is overrated. galaxy is kinda fast and its much more important that you understand your code and that its easy to work with it.
well, while loops might be a little bit faster, the question is
1) is it even noticeable? (no)
2) is it worth the additional work in gui?
everyone has to decide that for himself. for loops were just unusable bevore the fix since they totally f*cked up when nested.
if you look at a for loop in galaxy it looks like this:
the first three columns just set up the start, the end and the increment, what costs nearly zero performence.
then it continues with a while loop checking if the counter variable (i) is within bounds, if yes, it gets incremented and the actions are run. (if increment is < 0 it checks if its bigger the min, if its > 0 it checks if its smaller than max.)
also costs nearly zero performance since its just a integer comparison.
so in fact the only performance loss you might encounter are 1-2 integer comparisons per loop execution, what should be not noticable in any way. but yes, for perfect code do while loops.
for me personally its exactly the other way around. in the past i used while loops only, now i start working with for loops since they are well usable imo, especially if you have nested loops its saves some time when working.
its very useful. think of creating a new map initially supporting max players (so each player array should have size 16), but later you decide to make it max 8 players. if you have a record storing all player variable arrays u just change the size of the record to 8. if you have the variables in a folder you have to change the size to 8 for EACH single variable, what would result in alot of work depending on how many variables you got, since you cant use constants to define array sizes in gui.
for loops got fixed by blizzard a few versions back.
they are well usable now :)
but didnt know that either some weeks ago.
overall a nice guide that will be helpful for alot of beginners but also advanced mappers.