I'm writing this because I see a lot of the same questions regarding Galaxy asked several times, and I think it'd be useful to consolidate this information into one thread.
Q: What is Galaxy?
Galaxy is a C-like scripting language that Starcraft 2's triggers are coded in. The Trigger Editor GUI actually creates XML code that helps the editor generate the actual Galaxy to do the work.
If it's a trigger, it's programmed in Galaxy.
For those who are thinking of learning C to learn Galaxy, don't. Most of the time you'll spend learning C will be wasted because those features don't exist in Galaxy. If you're determined, skip everything regarding memory management and casting at least.
Q: Why should I care about Galaxy?
You probably don't have to. It all depends on your preferences. GUI is often described by non-technical users as easier to read and to use. It's certainly easier to get started with if you're new to programming. People who already have experience in programming languages may prefer Galaxy simply because it's what they're used to, and they don't have to click through the GUI windows.
There are a few things that GUI can't do that Galaxy can, also. But these are generally easily worked around by using custom script blocks.
Q: How can I learn Galaxy?
As with all things, practice makes perfect. Start by writing some basic triggers in the GUI. Then, click Data and hit View Script. The Script Editor will open and show you the generated Galaxy code. GUI is notorious for generating hard-to-read instructions, but it's a good starting point. You can see how to call GUI functions by clicking Data and then View Raw Data. This will show the normal method names as defined in Galaxy. Note: If the function isn't a native, then it's prefixed by libNtve_gf_
Q: I heard Galaxy has a 2 MB size limit. Is this true?
Yes, and no. Galaxy is only capable of addressing 2 MB worth of data due to the internal workings of it's code. This does not mean that you can't have more than 2 MB worth of triggers or .galaxy files. This limit is in terms of memory allocation. For example, an int is 4 bytes. It would take 524,288 ints before you reach this limit. For all practical purposes, you don't need to worry about this. If you do need to worry about this, chances are you're allocating memory irresponsibly. Avoid doing things like int[100][500] as it actually allocates 50,000 ints.
Q: Can I see a list of all the natives?
Here you go. This paste will help you with basic naming. I recommend you use GUI as a reference while you're learning, though. You can see how to call GUI functions by clicking Data and then View Raw Data. This will show the normal method names as defined in Galaxy. Note: If the function isn't a native, then it's prefixed by libNtve_gf_
Q: Can I do X with Galaxy?
Can you do it with GUI? If so, yes. If not, then the answer is still probably no. Galaxy isn't magic. Most "complex" system are just large problems that are broken down into smaller problems to solve the larger one. For example, I notice a lot of people asking how to give 10 minerals every minute to the player controlling a region, like in a King of the Hill-style map. A skilled programmer can break this into smaller parts, rather than just looking for one easy solution. He knows he needs to periodically, every 60 seconds, determine who is in control of the hill (create a region for the hill) and for each player, find out how many alive units are on the hill, and see who has the most. Then, he may reward the victor.
Q: How do I convert Text to String?
You don't. You can only concatenate them and compare their pointers for equality. If you want to work with texts and strings, convert the strings to text.
Q: Where's Game Links, players, dialogs, and other types that GUI had?
GUI lies about what the types of some things are. Game Links for example are all strings, and players are ints. "Marine" is the game-link of the Marine unit. If you need to figure out what's what, go to the GUI and see what the Preset type is, then go under the folder Support and find that type. If Raw Data is on, you'll see the real type.
Q: In GUI I saw an option for Threads, how does this work in Galaxy?
See above: GUI lies. There are no threads in GUI. What happens is the next event is run "pseudo-in-parallel" to the current one, rather than branching off, completing, and going back. Nothing in Galaxy can truly run in parallel. Thus, locking mechanisms are never needed. :)
Q: Is there something I can use for intellisense and editing, like in other languages?
Not officially, but grim001 made a really nice NotepadPlusPlus extension that handles intellisense as well as syntax highlighting for Galaxy. You can check it out here.
lets say I have more ints in variables than 500k, than the editor wont let me save the map or will it come up in the map? (I know I cant have variable higher than 500k int)
lets say I have more ints in variables than 500k, than the editor wont let me save the map or will it come up in the map? (I know I cant have variable higher than 500k int)
What exactly do you mean?
A) Do you mean you have an int with a very high number?
The maximum an int can store is 2,147,483,647 (2.1 billion) and the minimum is -2,147,483,648. If the number is larger it'll show when you try to save or test the map.
B) Do you mean you have 500,000 integers?
At some point the map has filled up all allowed memory. If that happens then it'll show when you try to save or test the map.
PS: If you have any more questions then PM me or make a new topic.
I'll lock this F.A.Q. so it doesn't get crowded with messages.
Do you use Galaxy language to create a custom script for AI in the AI section of the editor? By AI section I mean the new AI section, not related to the attack wave in trigger section.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I'm writing this because I see a lot of the same questions regarding Galaxy asked several times, and I think it'd be useful to consolidate this information into one thread.
Q: What is Galaxy?
Galaxy is a C-like scripting language that Starcraft 2's triggers are coded in. The Trigger Editor GUI actually creates XML code that helps the editor generate the actual Galaxy to do the work.
If it's a trigger, it's programmed in Galaxy.
For those who are thinking of learning C to learn Galaxy, don't. Most of the time you'll spend learning C will be wasted because those features don't exist in Galaxy. If you're determined, skip everything regarding memory management and casting at least.
Q: Why should I care about Galaxy?
You probably don't have to. It all depends on your preferences. GUI is often described by non-technical users as easier to read and to use. It's certainly easier to get started with if you're new to programming. People who already have experience in programming languages may prefer Galaxy simply because it's what they're used to, and they don't have to click through the GUI windows.
There are a few things that GUI can't do that Galaxy can, also. But these are generally easily worked around by using custom script blocks.
Q: How can I learn Galaxy?
As with all things, practice makes perfect. Start by writing some basic triggers in the GUI. Then, click Data and hit View Script. The Script Editor will open and show you the generated Galaxy code. GUI is notorious for generating hard-to-read instructions, but it's a good starting point. You can see how to call GUI functions by clicking Data and then View Raw Data. This will show the normal method names as defined in Galaxy. Note: If the function isn't a native, then it's prefixed by libNtve_gf_
Q: I heard Galaxy has a 2 MB size limit. Is this true?
Yes, and no. Galaxy is only capable of addressing 2 MB worth of data due to the internal workings of it's code. This does not mean that you can't have more than 2 MB worth of triggers or .galaxy files. This limit is in terms of memory allocation. For example, an int is 4 bytes. It would take 524,288 ints before you reach this limit. For all practical purposes, you don't need to worry about this. If you do need to worry about this, chances are you're allocating memory irresponsibly. Avoid doing things like int[100][500] as it actually allocates 50,000 ints.
Q: Can I see a list of all the natives?
Here you go. This paste will help you with basic naming. I recommend you use GUI as a reference while you're learning, though. You can see how to call GUI functions by clicking Data and then View Raw Data. This will show the normal method names as defined in Galaxy. Note: If the function isn't a native, then it's prefixed by libNtve_gf_
Q: Can I do X with Galaxy?
Can you do it with GUI? If so, yes. If not, then the answer is still probably no. Galaxy isn't magic. Most "complex" system are just large problems that are broken down into smaller problems to solve the larger one. For example, I notice a lot of people asking how to give 10 minerals every minute to the player controlling a region, like in a King of the Hill-style map. A skilled programmer can break this into smaller parts, rather than just looking for one easy solution. He knows he needs to periodically, every 60 seconds, determine who is in control of the hill (create a region for the hill) and for each player, find out how many alive units are on the hill, and see who has the most. Then, he may reward the victor.
Q: How do I convert Text to String?
You don't. You can only concatenate them and compare their pointers for equality. If you want to work with texts and strings, convert the strings to text.
Q: Where's Game Links, players, dialogs, and other types that GUI had?
GUI lies about what the types of some things are. Game Links for example are all strings, and players are ints. "Marine" is the game-link of the Marine unit. If you need to figure out what's what, go to the GUI and see what the Preset type is, then go under the folder Support and find that type. If Raw Data is on, you'll see the real type.
Q: In GUI I saw an option for Threads, how does this work in Galaxy?
See above: GUI lies. There are no threads in GUI. What happens is the next event is run "pseudo-in-parallel" to the current one, rather than branching off, completing, and going back. Nothing in Galaxy can truly run in parallel. Thus, locking mechanisms are never needed. :)
Q: Is there something I can use for intellisense and editing, like in other languages?
Not officially, but grim001 made a really nice NotepadPlusPlus extension that handles intellisense as well as syntax highlighting for Galaxy. You can check it out here.
lets say I have more ints in variables than 500k, than the editor wont let me save the map or will it come up in the map? (I know I cant have variable higher than 500k int)
I was thinking about B answer.D
What exactly do you mean?
A) Do you mean you have an int with a very high number? The maximum an int can store is 2,147,483,647 (2.1 billion) and the minimum is -2,147,483,648. If the number is larger it'll show when you try to save or test the map.
B) Do you mean you have 500,000 integers? At some point the map has filled up all allowed memory. If that happens then it'll show when you try to save or test the map.
PS: If you have any more questions then PM me or make a new topic.
I'll lock this F.A.Q. so it doesn't get crowded with messages.
Do you use Galaxy language to create a custom script for AI in the AI section of the editor? By AI section I mean the new AI section, not related to the attack wave in trigger section.