The reason why you want to do this yourself, and not put it on the compiler, is because the compiler doesn't initially know what kind of cleanup to call. I believe the compiler's cleanup code is a couple thousand lines of assembly that all need to be checked before the break statement can be called. In C and C variations, this is called by a thread. Eventually, this thread will be completed and all data can be restored. This is why there is so much more data leaks in C than in Java. In Java, this code is not called in a thread. It is all run before the program continues to run, making sure that there are no data leaks. In Java, all this does is slow the program down slightly. The cleanup system terminates everything that needs to be, and the program continues in less than 1/100 of a second (because it is an assembly code, not a class). In C#, this is never 100% cleaned up properly. The way C# cleans up actually makes using this thread take longer.
What cleanup?
As far as I know the break statement (at least in C) is realized as a simple jump order in assembler. Just as all kinds of loops ultimately boil down to JMPs too.
What is the best way to profile one's code? By profile I mean figure out what parts of the code are slower than the rest? There are all sorts of profiling tools for common languages like C, Java, etc, but I'm not sure if there are any tools available to SC2 modders? I mean, let's just get right to the bottom of this and figure out what takes longer to run and when...
Profiling is much less important for us, because Galaxy is just a language inside a program.
Performance is needed for Sc2 to be able to reach high FPS on weak machines. So it isn't enough that it just doesn't lag, but you want to squeeze out as much performance as you can.
For us, however, it's different. As long as our code doesn't cause lags (lag = so much code needs to be executed that our computer cannot do it "instantly") there's nothing to worry about performance-wise.
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.
I would say it is a better habit to use the control structure that are best suited for the particular situation.
There is nothing wrong in using for-loops. Not for beginners and not for professionals.
If you need a loop that loops over a certain range of numbers then a for-loop is a much more natural and better choice.
I mean it's obvious which snippet is overly complicated. It's a bit less drastic in for-each-integer loops. But the same idea still applies. Use what makes your code most clear and readable. Care about performance or "power" last.
(It's not GUI, but I haven't worked with GUI in a long time so I can't remember the exact names and syntax).
Well, I frown a bit on the use of "always", "never", "do not", etc.
But all in all it's a nice write-up and a fair amount of unarguably good coding practice.
You say to use action definitions instead of triggers but I can't find out how to tell it to run the action definition. I'm use to just setting up triggers.
I got a couple of questions regarding with actions. How many actions can you run with one trigger? If 500 triggers is bad. What about 1 trigger with 500 actions? What is the difference between a trigger with action definition that has 500 actions towards a trigger with 500 actions?
Im saying 500 for the amount because it seems ridiculous to have that many actions going on but it can happen.
C and C variations have an incredibly basic cleanup, more commonly referred to as "deletion". In Java, the cleanup does a bunch of behind the scenes stuff. In C and C variations, what I mean by cleanup is just deletion. This deletion is in a thread, as it takes time to delete an object (C+ + and C#, obviously not referring to C for the object deletion). In C, it is even more primitive. The "cleanup" I refer to is just destroying data that is no longer needed. C doesn't do this automatically, (as you C programmers know, can get extremely annoying).
All I am saying is that the deletion of the files is run in a thread in C, but not in Java. There are reasons, as I sort of explained in my last post, for each of these setups. And nes. (Yes/No) The break statement skips ahead in the program, but leaves whatever data and instances that were still being run behind. This can be problematic, and needs to be taken care of by the compiler. In Java, this is automatically dealt with. In C#, not so much, which is why I was saying telling the compiler what data it needs to delete can be as effective if not more effective than a while loop.
For new coders: USE WHILE LOOPS, or for loops with NO BREAK statements. They just cause too many problems if you don't know how to deal with them.
I got a couple of questions regarding with actions. How many actions can you run with one trigger? If 500 triggers is bad. What about 1 trigger with 500 actions? What is the difference between a trigger with action definition that has 500 actions towards a trigger with 500 actions? Im saying 500 for the amount because it seems ridiculous to have that many actions going on but it can happen.
Better have a few longer triggers than a ton of small ones.
HOWEVER - it's even more important to keep things clean and clear.
Don't force yourself to combine triggers just to save some bits of memory.
Don't add more actions into a trigger than you can overlook.
Group actions that you're using often into functions/action definitions.
As to how many actions you CAN have in a trigger - a lot. But at some point the editor starts slowing down horribly when viewing that trigger.
I have done copy-pasting to triggers between maps. Sometimes I get error message (don't know exact wording) like: "missing parameter in trigger X".
For example if I copy trigger that order unit to use ability from another map values are missing because lets say that pleplaced SCV is not in that map you are copying your trigger.
Is it possible to "update" map triggers so that all "linking" to old map is gone? I'm also intrested about how to reset map / editor settings.
Sorry for bad explanation. I mean in code level it causes problems to copy-paste things, right?
In short: Should I stop copy-pasting triggers? Is it better just to look how trigger is done and then redone that trigger to my own map?
I've just now noticed that float multiplication is really really bad and off and division is rather accurate.
Curiosly I remember it being the other way around...
Sorry to necro this But could you also mention that parameters in functions are passed from the trigger(as in you set their values there, not just as you say it infromation that you put in, thats not descriptive enough of how awesome they are). When i first started using the editor i thought it was the same as using a variable in the trigger(you know set it in the trigger using the set variable function), only it was like a global variable, and so i thought screw functions i might as well just use triggers. But then later i found out that it's a hell of a lot easier to use parameters than it is to use variables.
Sorry to necro this But could you also mention that parameters in functions are passed from the trigger(as in you set their values there, not just as you say it infromation that you put in, thats not descriptive enough of how awesome they are).
That is basically the same message just explained differently. And good programing must use Parameters and Variables in harmony. Necro response xD
I'm relatively new to programming, but I've spent a few years working with the data and trigger editors to know my way around. However, I don't understand Records. When I try to use them, it doesn't work for my maps, because I need to perform arithmetic on most of my variables. If I try to do that, I can't because it won't let me use functions. Also, the variable I set to link to the record has no value, and it won't let me change it. Would someone mind explaining how these things work?
Not sure what your asking exactly, give an example. But a record in programming is something like a struct in the C programming langauge. Basically say you want to have a collection of information on a group of 30 people. You create a record or struct like this:
This can be done by making a new record by clicking the record in the trigger editor and then adding variables to the record. Now you have a struct called person, this is not a variable in of itself, it is a new type of variable that you have just defined. In order to use this you must declare a variable of type person. In starcraft you could make a variable called Friends[30] and make it of type -record which can be found at the very top of the list and when you select that i believe you will get a new category called Record: and here you select the record type you want to use for the variable in this case person. Then if you wanted to change your first friends hairColor you would write Friends[0].hairColor = "Brown"; or change their height Friends.[0].height = 6.25 or friends[0].weight = 200. If you know anything about databases a struct can be thought of as a record in the database, each record has a name, height, weight value etc.
Records/Structs can be very useful, even if you have no need for storing any of this kind of information, you can still use records to keep the number of global variables down. In a map im working on now, there is a lot of code and i have to store all my globals in respective records or whenever i went to use a variable i would have to find it in a massive list, it would just be very unorganized. If you use a record properlly as i have just desecribed i dont think you will have any of the problems your talking about.
Overall useful though your dogmatic inclination towards while loops and condemnation of for loops is bothersome and has no legitimate grounds. Hence the name though, I guess...
Overall useful though your dogmatic inclination towards while loops and condemnation of for loops is bothersome and has no legitimate grounds. Hence the name though, I guess...
The initial implementation of loops was horrible. The problem is described here. Blizzard fixed it in some patch making for-loops more efficient. Now I would advise people to use for-loops as they are slightly faster to code than a while.
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.
This is has just destroyed my limited knowledge of the trigger editor.
I didnt even know records existed, and they seem veryyyyyyyy nice and fancy but will take some time learning how to use
i didnt even know Functions existed, and they seem very weird not having triggers and will also take some time learning how to use
I didnt know you could use less than 10 triggers for an entire map, iv used triggers since i was 9 (im 15 now) and i cant imagine using records instead of triggers as iv adapted to using them
I didnt know you could use loops to do practically everything, as before i had done things for each player which is obviously hideous lol and why my maps started to lag
I obviously need to do some more research and stop teaching myself how to use the editor, if anyone could throw more info my way it would be highly apreciated
I've started on an intro to the trigger editor tutorial (see my sig), but I still need to find the time to complete it. that being said, http://wiki.sc2mapster.com/Tutorials has a great amount of trigger ones, in your case I recommend the presets and records one, and the presets and multidimensional arrays one.
What cleanup?
As far as I know the break statement (at least in C) is realized as a simple jump order in assembler. Just as all kinds of loops ultimately boil down to JMPs too.
Profiling is much less important for us, because Galaxy is just a language inside a program.
Performance is needed for Sc2 to be able to reach high FPS on weak machines. So it isn't enough that it just doesn't lag, but you want to squeeze out as much performance as you can.
For us, however, it's different. As long as our code doesn't cause lags (lag = so much code needs to be executed that our computer cannot do it "instantly") there's nothing to worry about performance-wise.
I would say it is a better habit to use the control structure that are best suited for the particular situation.
There is nothing wrong in using for-loops. Not for beginners and not for professionals.
If you need a loop that loops over a certain range of numbers then a for-loop is a much more natural and better choice.
I mean it's obvious which snippet is overly complicated. It's a bit less drastic in for-each-integer loops. But the same idea still applies. Use what makes your code most clear and readable. Care about performance or "power" last.
(It's not GUI, but I haven't worked with GUI in a long time so I can't remember the exact names and syntax).
Well, I frown a bit on the use of "always", "never", "do not", etc.
But all in all it's a nice write-up and a fair amount of unarguably good coding practice.
You say to use action definitions instead of triggers but I can't find out how to tell it to run the action definition. I'm use to just setting up triggers.
I got a couple of questions regarding with actions. How many actions can you run with one trigger? If 500 triggers is bad. What about 1 trigger with 500 actions? What is the difference between a trigger with action definition that has 500 actions towards a trigger with 500 actions? Im saying 500 for the amount because it seems ridiculous to have that many actions going on but it can happen.
@Keyeszx: Go
to run action definition, just create new action in your trigger and search the name of your action definition.
@s3rius: Go
C and C variations have an incredibly basic cleanup, more commonly referred to as "deletion". In Java, the cleanup does a bunch of behind the scenes stuff. In C and C variations, what I mean by cleanup is just deletion. This deletion is in a thread, as it takes time to delete an object (C+ + and C#, obviously not referring to C for the object deletion). In C, it is even more primitive. The "cleanup" I refer to is just destroying data that is no longer needed. C doesn't do this automatically, (as you C programmers know, can get extremely annoying).
All I am saying is that the deletion of the files is run in a thread in C, but not in Java. There are reasons, as I sort of explained in my last post, for each of these setups. And nes. (Yes/No) The break statement skips ahead in the program, but leaves whatever data and instances that were still being run behind. This can be problematic, and needs to be taken care of by the compiler. In Java, this is automatically dealt with. In C#, not so much, which is why I was saying telling the compiler what data it needs to delete can be as effective if not more effective than a while loop.
For new coders: USE WHILE LOOPS, or for loops with NO BREAK statements. They just cause too many problems if you don't know how to deal with them.
Great to be back and part of the community again!
Better have a few longer triggers than a ton of small ones.
HOWEVER - it's even more important to keep things clean and clear.
Don't force yourself to combine triggers just to save some bits of memory.
Don't add more actions into a trigger than you can overlook.
Group actions that you're using often into functions/action definitions.
As to how many actions you CAN have in a trigger - a lot. But at some point the editor starts slowing down horribly when viewing that trigger.
I was taught that if you know the outcome of the loop you want to use, use the For Loop.
If you don't or are uncertain about the outcome, use While loops.
I have done copy-pasting to triggers between maps. Sometimes I get error message (don't know exact wording) like: "missing parameter in trigger X".
For example if I copy trigger that order unit to use ability from another map values are missing because lets say that pleplaced SCV is not in that map you are copying your trigger.
Is it possible to "update" map triggers so that all "linking" to old map is gone? I'm also intrested about how to reset map / editor settings.
Sorry for bad explanation. I mean in code level it causes problems to copy-paste things, right?
In short: Should I stop copy-pasting triggers? Is it better just to look how trigger is done and then redone that trigger to my own map?
@Terhonator: Go
Yes. Molding a trigger to your needs is the best. Copy/Paste is bad. Never do that. Study, adapt and code.
I've just now noticed that float multiplication is really really bad and off and division is rather accurate.
Curiosly I remember it being the other way around...
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
That is basically the same message just explained differently. And good programing must use Parameters and Variables in harmony. Necro response xD
I'm relatively new to programming, but I've spent a few years working with the data and trigger editors to know my way around. However, I don't understand Records. When I try to use them, it doesn't work for my maps, because I need to perform arithmetic on most of my variables. If I try to do that, I can't because it won't let me use functions. Also, the variable I set to link to the record has no value, and it won't let me change it. Would someone mind explaining how these things work?
New to the Editor? Need a tutorial? Click Here
Want data assets? Click Here
@fishy77: Go
Not sure what your asking exactly, give an example. But a record in programming is something like a struct in the C programming langauge. Basically say you want to have a collection of information on a group of 30 people. You create a record or struct like this:
Struct person{ String name; String hairColor; String eyeColor; String job; double height; int weight; };
This can be done by making a new record by clicking the record in the trigger editor and then adding variables to the record. Now you have a struct called person, this is not a variable in of itself, it is a new type of variable that you have just defined. In order to use this you must declare a variable of type person. In starcraft you could make a variable called Friends[30] and make it of type -record which can be found at the very top of the list and when you select that i believe you will get a new category called Record: and here you select the record type you want to use for the variable in this case person. Then if you wanted to change your first friends hairColor you would write Friends[0].hairColor = "Brown"; or change their height Friends.[0].height = 6.25 or friends[0].weight = 200. If you know anything about databases a struct can be thought of as a record in the database, each record has a name, height, weight value etc.
Records/Structs can be very useful, even if you have no need for storing any of this kind of information, you can still use records to keep the number of global variables down. In a map im working on now, there is a lot of code and i have to store all my globals in respective records or whenever i went to use a variable i would have to find it in a massive list, it would just be very unorganized. If you use a record properlly as i have just desecribed i dont think you will have any of the problems your talking about.
@lemmy734: Go
I think I understand it now. It is very useful. I'll be sure to use it from now on.
New to the Editor? Need a tutorial? Click Here
Want data assets? Click Here
Overall useful though your dogmatic inclination towards while loops and condemnation of for loops is bothersome and has no legitimate grounds. Hence the name though, I guess...
The initial implementation of loops was horrible. The problem is described here. Blizzard fixed it in some patch making for-loops more efficient. Now I would advise people to use for-loops as they are slightly faster to code than a while.
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.
This is has just destroyed my limited knowledge of the trigger editor.
I obviously need to do some more research and stop teaching myself how to use the editor, if anyone could throw more info my way it would be highly apreciated
@BozoOvermind: Go
I've started on an intro to the trigger editor tutorial (see my sig), but I still need to find the time to complete it. that being said, http://wiki.sc2mapster.com/Tutorials has a great amount of trigger ones, in your case I recommend the presets and records one, and the presets and multidimensional arrays one.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)