Hello, recently I have started learning Andromeda (a language extension for galaxy) but my programming experience is just preliminary with Java, C and other various languages. Although I know quite a variety of languages, I only coded small things and fixed bugs in other scripts so I never really started any grand project.
One problem I encountered in my attempt at a grand project, was how to script functions that ran based on conditions?
I'm fine with all the scripting within functions, but say I want a certain function to run when unit has entered region "x"... how would one do so?
I think its mainly because of my lack of understanding how scripts are read by the computer...
I understand how it is read from top to bottom, therefore you need to define/declare certain things before you use them. I also understand how you write functions and call them within other functions/etc. But how would you... uh, not sure if this is the right word, dynamically call the functions?
In the GUI, all you need to do was create a trigger, set the event, then do whatever in the actions. So basically my question concerns how to script events (not about creating new events) so that it will run function "doSomething()" when the specified event occurs.
From what i understand the booleans testconds is used in cases where you want to do "Run Trigger Checking Conditions, Ignore Conditions".
Same case with runActions, as you may just want to evaluate the conditions. The if loops that check them are not necessary if you will never do such checks.
If you want your custom script to run on game init just fill in the name of the initialization function at the bottom of the custom script block. In my case is init(). so I will put init
Hope I answered your questipn =/ You can press Ctrl + F11 to see galaxy script of your GUI triggers as well to see how they are compiled by the galaxy editor.
Thanks a bunch for the guidance. Although it does answer my question in a way, I'm afraid that wasn't really what I was looking for...
After looking at some of s3rius scripts over the forums you don't really need the "testConds" and "runActions"... I was wondering how script events without following the trigger format. Sorry for the lack of clarification.
Hmm... I think my phrasing has displaced my actual meaning.
I only referred to trigger events as a reference to support what I was asking for. Like how triggers are just functions in galaxy, I don't intend to mimic creating a function and its respective events.
To clear any misunderstandings, what I'm asking for is how to write a function such that if certain conditions are true, that function will run its contents. Again, this is due to my lack of understanding of how programming works... I just don't understand how it runs through the code... does programs run through the compiled code every 0.01 seconds? If that is true, I can just place a if-then statement to run functions... but I don't see how that is effective for CPU usage... so I disregarded that thought.
does programs run through the compiled code every 0.01 seconds?
A function is only executed if it is called. It doesn't run every 0.01 seconds, unless you have a periodic event that calls your function.
Yes, you are right on this one, it will be quite wasteful on CPU usage.
When a function is called, the lines in it are run in sequence, top to bottom.
To have a function that only runs its contents if it is true, I believe it's as simple as using a return statement.
When a function is called, a "thread" is created. The return statement tells a function to terminate a "thread" and return to its caller.
In the example above, if he conditions are not met, the function will return and ignore the actions.
Forgive me for any confusion.. i really suck at understanding questions and explaining stuffl. ><
"void" from my understanding means there is no return type? So the code runs from top to bottom and sees the code in your post...
Let's say when it ran through the conditions are not met and it skips out of the function... what if the conditions are met after running the function? I understand when we actually script this that it will run when the conditions are met, but I can't comprehend how it works! If the entire code file is only ran once from top to bottom, how does it check the condition when it is indeed true?
No probs mate. Yeap, void means no return type, thus we "return;" if we want to skip remaining actions. "return true;" would instead be used if the function was a bool type.
I don't think it's entirely correct to say that the entire code is run only once from top to bottom. When we finish programming our functions we "Compile" them. Once compiled you could say the functions are stored into the PC's memory whenever we load the map to be called later. Here's how I understand it... If I'm wrong I do encourage someone to come along and correct me.
Whenever an event fires and triggers a function, only that function will run once from top to bottom.
If I type -test, a thread will be created for Function A, once it finishes its run, it will return to main() (though im not too sure what main() is in galaxy >_>)
When a function is called, it will always execute/check only what is within its curly braces { }
Function B will create a thread every 1 second and check conditions inside it.
So every time a function is run/called, it will recheck the conditions inside it.
To have a code that is called once but continuously checks for conditions to run actions, I would do this:
Thanks for clearing up most of the aspects of how it works.
Considering only the functions...
Concerning the actual conditions for Function A, B and C. Wouldn't the program have to run whatever is inside the curly braces for every single function every time any action is done to check for any conditions that matches with the action?
For example:
Function A - When I type "-test"
Function B - When I type "-test2"
Funciton C - When I move unit X
Be it a similar or completely different function, each function must be ran first to check for the conditions... because condition checks are within curly braces.
And what if you have a void function which checks for these conditions but you don't want it to be ran when triggered, only when you call on it (while conditions are true)? How does it differentiate? I think my questions are now deviating from SC2 and more into actual Galaxy or just programming as a whole, sorry about that.
Considering "Whenever an event fires and triggers a function"...
This is exactly what I'm confused about... if you need a function that checks for a condition to run a function... and another function to run that previous function... its sort of like a endless loop of logic. That "event" is ultimately another function right? Just like how in GUI many of the presets or special data types are actually just strings.
Considering "Whenever an event fires and triggers a function"... This is exactly what I'm confused about... if you need a function that checks for a condition to run a function... and another function to run that previous function... its sort of like a endless loop of logic. That "event" is ultimately another function right? Just like how in GUI many of the presets or special data types are actually just strings.
It is true that Events are basically functions (but a certain kind of functions. More about that below), and that there is some kind of endless loop in the fact that you need a function to call a function.
If you think about it - it's stange that anything actually works in a map since you have no starting point.
However, there is one function in every map which is executed once the map starts. You don't have to call it yourself. The function is called InitMap().
Since you've been working with Java and C you might have noticed that basically every program has a main() function. InitMap() serves the same purpose.
That's how it looks like:
It calls several different functions that basically initialize the map. For example in InitTriggers() all the GUI triggers are created and linked to events.
InitCustomScript is of particular importance when you're scripting. You can order this function to run some of your own functions and thus get your map rolling.
You can't, however, change any of these functions by hand. You can set-up an initializer function in each of your custom script sections. These initializers will then automatically be called in InitTriggers().
So in there you could, for example, start some of your triggers or functions to spawn units, or do whatever.
I don't think it's entirely correct to say that the entire code is run only once from top to bottom. When we finish programming our functions we "Compile" them. Once compiled you could say the functions are stored into the PC's memory whenever we load the map to be called later. Here's how I understand it... If I'm wrong I do encourage someone to come along and correct me.
Now, this isn't exactly true. Compilation turns our script into a different computer language that the game can understand. That process isn't of any particular interest to us.
Most of the functions that we don't write ourselfs are natives (all blue-colored functions are natives). Natives communicate with the game itself to do things. If we call the UnitKill native, then this function tells the game to kill a certain unit, so this process basically doesn't happen within our code. We just give the order.
All the events are natives too. They tell the game that it should run a certain function when something happens.
E.g. the TriggerAddEventUnitDied tells the game it should run the associated function if a certain unit died. Our Galaxy script itself can't find out whether a unit is dead or not, it always needs to communicate with the game itself.
The game is much more sophisticated than our primitive script and has no problems noticing when a unit dies, a timer runs out or the world explodes. It can then tell our triggers that a certain thing happened.
Our functions are stored in the computer's memory, but only when we start playing the map (=loading it) and not when we're compiling (=saving) it. But just because they're loaded into memory doesn't mean they're set in store, by the way. You can very conveniently add events on the run:
voidCreateUnit2(intplayer,stringunittype,pointposition){//We call a native to create a unit. No idea if the parameters are correct^^UnitCreate(1,unittype,0,player,point,270);//Now we add our unit's death as an event to some triggerTriggerAddEventUnitDied(gt_SomeDeathTrigger,UnitLastCreated());}
Very useful stuff. Just wanted to throw it in, since that's something you don't learn when using GUI.
And what if you have a void function which checks for these conditions but you don't want it to be ran when triggered, only when you call on it (while conditions are true)? How does it differentiate? I think my questions are now deviating from SC2 and more into actual Galaxy or just programming as a whole, sorry about that.
What exactly do you mean by that? Of course you can run a function just like normal and make it check for conditions, but keep in mind that you can't use event responses (EventUnit(), EventPlayer(), etc) since there was no event starting the function. So you have to supply parameters for the function another way.
Considering only the functions... Concerning the actual conditions for Function A, B and C. Wouldn't the program have to run whatever is inside the curly braces for every single function every time any action is done to check for any conditions that matches with the action?
That's basically what the game is doing. The entire Sc2 (and most other games) is basically just one giant loop that runs over and over and over.
Keep in mind that the game does everything that happens in the game. So it indirectly causes all the events to happen.
So basically just everytime something happens that could be caught by an event the game checks it: Is there any event that is linked to that object? No? Then never mind. Yes? Then call the associated function.
Of course the game knows all the things that can trigger events, so it knows which to check and which not to.
You can't, however, change any of these functions by hand. You can
set-up an initializer function in each of your custom script sections.
These initializers will then automatically be called in InitTriggers().
So in there you could, for example, start some of your triggers or
functions to spawn units, or do whatever.
How would I include the initializer function if I'm coding outside of SC2? Currently my setup is coding in Notepadplusplus with Andromeda syntax and then compiling with Andromeda which also injects my code into a specific map as an import.
Or is it reverse psychology for the sake of user-friendliness?
What I mean is, that we write a initializer function that includes the functions or things done instead of the other way around. So we write a function that starts with "Init", it gets marked and included in InitTriggers() which will then be ran during map initialization (Is that right?). I think this is what the includer does in the GUI instead of having some marker within the function to tell it to be included by "InitXYZ" which is then generated during compilation as it suggests in the GUI.
Our functions are stored in the computer's memory, but only when we start playing the map (=loading it) and not when we're compiling (=saving) it. But just because they're loaded into memory doesn't mean they're set in store, by the way. You can very conveniently add events on the run:
voidCreateUnit2(intplayer,stringunittype,pointposition){//We call a native to create a unit. No idea if the parameters are correct^^UnitCreate(1,unittype,0,player,point,270);//Now we add our unit's death as an event to some triggerTriggerAddEventUnitDied(gt_SomeDeathTrigger,UnitLastCreated());}
Thats pretty neat, I'll be using this quite a lot.
Concerning gt_SomeDeathTrigger, is the parameter limited to global triggers? If not, does everything else gets automatically included when I use function TriggerAddEventXYZ for any function I write? (In other words do I need to write anything else after adding the event within a function, other than the actual function that is ran when the event is triggered?)
What exactly do you mean by that? Of course you can run a function just
like normal and make it check for conditions, but keep in mind that you
can't use event responses (EventUnit(), EventPlayer(), etc) since there
was no event starting the function. So you have to supply parameters for
the function another way.
Haha, sorry for the confusion. You already answered this by in the next paragraph by clearing up one of my misunderstandings of the how it worked. Thanks!
And FuzzyD, you've been a great help too. Thanks a bunch! :)
How would I include the initializer function if I'm coding outside of SC2? Currently my setup is coding in Notepadplusplus with Andromeda syntax and then compiling with Andromeda which also injects my code into a specific map as an import.
In Andromeda you can put code in a static block to have it run on initialization.
static{// code goes here}
You don't need to worry about the InitMap() function with Andromeda - the only important thing is that the init map function calls the initialization for Andromeda, which will handle all of your code.
Quote:
Thats pretty neat, I'll be using this quite a lot. Concerning gt_SomeDeathTrigger, is the parameter limited to global triggers? If not, does everything else gets automatically included when I use function TriggerAddEventXYZ for any function I write? (In other words do I need to write anything else after adding the event within a function, other than the actual function that is ran when the event is triggered?)
Trigger variables do not need to be global - once an event has been passed a trigger you can get rid of the trigger variable if you want - the only reason to keep the variable is if you will need it later on, for instance adding it to another event or something. In fact if you wanted to you could place the call to TriggerCreate() directly in an event binding.
By the way, I tried searching online and researching, but what exactly are enrichments and what are they used for?
Is it something like allocating some attributes/properties to a class?
By the way, I tried searching online and researching, but what exactly are enrichments and what are they used for? Is it something like allocating some attributes/properties to a class?
sc2mod is the home of Andromeda, it's a good place to ask questions specific to it.
Enrichments are basically a way to add functionality to a type. For example, if I had an enrichment on the type unit called "getHP," I could then use any unit variable name along with that enrichment to get its hp. For example:
unitmyUnit;inthp;// might be fixed, I can't rememberhp=myUnit.getHP();
Even though unit is not a class, the enrichment allows me to define some class like functionality for it, instead of a traditional C approach which would be the following:
unitmyUnit;inthp;// might be fixed, I can't rememberhp=getUnitHP(myUnit);
Vermore, it appears to me that you do not quite have a solid understanding computer programming. I would highly recommend a foundation based on C and C++ or Java before delving into Andromeda. Andromeda is really meant for those who are proficient in such programming languages, as well as Galaxy (which is really just C--). You will find plenty of information online on how C, C++, and Java work.
As AzothHyjal said, sc2mod.com is the home of Andromeda. There, you will find the full documentation, instructions for use, coding guidelines, etc... as well as forums for asking any Andromeda specific questions you may have. As I mentioned before, however, users are generally expected to be familiar with at least Galaxy and an object-oriented language such as C++ or Java.
Despite all my criticism, I applaud your efforts to go beyond the clumsy tools Blizzard has given us in their Galaxy Editor. I think that scripting is the way to go when making custom maps, as it is the most powerful and the most efficient, in the hands of a skilled programmer. You have a ways to go, and I wish you luck.
Thanks AzothHyjal and fernsauce, I recognize them from Java! Now I know what they are called... :s
@XPilot: Go
Hello XPilot! Haha, thank you. My school doesn't provide computer science and I'm not in university yet so I never got the chance to learn it properly... When I started programming I just wrote programs by deducing how it works from examples, so my understanding and vocabulary are down in the pits.
I'm currently watching lectures from Stanford and MIT to improve my foundation.
I kinda learned the same way you are learning now. Looking at examples and pulling them apart like a puzzle. Reverse engineering is the way to go :P You'll tend to learn some nifty tricks here and there simply from looking at codes other than your own.
How would I include the initializer function if I'm coding outside of SC2? Currently my setup is coding in Notepadplusplus with Andromeda syntax and then compiling with Andromeda which also injects my code into a specific map as an import.
Or is it reverse psychology for the sake of user-friendliness? What I mean is, that we write a initializer function that includes the functions or things done instead of the other way around. So we write a function that starts with "Init", it gets marked and included in InitTriggers() which will then be ran during map initialization (Is that right?). I think this is what the includer does in the GUI instead of having some marker within the function to tell it to be included by "InitXYZ" which is then generated during compilation as it suggests in the GUI.
If you're modifying the map script directly then you can use a static{} block like Azoth said. That one only works for Andromeda.
Otherwise you can just write one of your init functions in the InitMap or InitTriggers functions. You gotta include it manually then.
If you mean by the second paragraph that all functions that start with Init will get included - no. Name has nothing to do with it. I could also call it TieMyShoes().
Thats pretty neat, I'll be using this quite a lot. Concerning gt_SomeDeathTrigger, is the parameter limited to global triggers? If not, does everything else gets automatically included when I use function TriggerAddEventXYZ for any function I write? (In other words do I need to write anything else after adding the event within a function, other than the actual function that is ran when the event is triggered?)
No, triggers do not need to be global.
Dynamically creating triggers can sometimes be very useful. For example when you have a large RPG with a dozen heroes. Each of the hero uses a different set of triggers (e.g. for skills and stuff). No need to create triggers for heroes that no one has chosen.
This is basically replacing what GUI calls Action definitions.
If I want to run a function with Waits in it, but don't want the parent function (the one that's calling it) to wait for it being executed then I can just pass the name of the function to this one. It creates a trigger, runs it and destroys it immedidately after. Nice, clean, great.
Well, comes time comes knowledge.
If you stick with learning Galaxy then you'll soon understand everything.
With regards to TriggerDestroy(t),
I suppose its good practice to destroy all trigger variables after they are used? Or is galaxy smart enough to help us collect and dump garbage. I know this is a little off topic here but i'm wondering if there are any variable types that can potentially leak. In JASS it was points and units i believe, always had to null them after usage.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello, recently I have started learning Andromeda (a language extension for galaxy) but my programming experience is just preliminary with Java, C and other various languages. Although I know quite a variety of languages, I only coded small things and fixed bugs in other scripts so I never really started any grand project.
One problem I encountered in my attempt at a grand project, was how to script functions that ran based on conditions? I'm fine with all the scripting within functions, but say I want a certain function to run when unit has entered region "x"... how would one do so?
I think its mainly because of my lack of understanding how scripts are read by the computer... I understand how it is read from top to bottom, therefore you need to define/declare certain things before you use them. I also understand how you write functions and call them within other functions/etc. But how would you... uh, not sure if this is the right word, dynamically call the functions?
In the GUI, all you need to do was create a trigger, set the event, then do whatever in the actions. So basically my question concerns how to script events (not about creating new events) so that it will run function "doSomething()" when the specified event occurs.
Thanks.
Best Regards, Vermore
If i'm understanding your question right, the syntax is something like this,
From what i understand the booleans testconds is used in cases where you want to do "Run Trigger Checking Conditions, Ignore Conditions". Same case with runActions, as you may just want to evaluate the conditions. The if loops that check them are not necessary if you will never do such checks.
If you want your custom script to run on game init just fill in the name of the initialization function at the bottom of the custom script block. In my case is init(). so I will put init
Hope I answered your questipn =/ You can press Ctrl + F11 to see galaxy script of your GUI triggers as well to see how they are compiled by the galaxy editor.
Thanks a bunch for the guidance. Although it does answer my question in a way, I'm afraid that wasn't really what I was looking for...
After looking at some of s3rius scripts over the forums you don't really need the "testConds" and "runActions"... I was wondering how script events without following the trigger format. Sorry for the lack of clarification.
Ah okay. I believe the bare minimum is
Unless theres a way to attach events directly to a non-trigger function, I don't think its possible. AFAIK, an event must be attached to a trigger. =/
Hmm... I think my phrasing has displaced my actual meaning.
I only referred to trigger events as a reference to support what I was asking for. Like how triggers are just functions in galaxy, I don't intend to mimic creating a function and its respective events.
To clear any misunderstandings, what I'm asking for is how to write a function such that if certain conditions are true, that function will run its contents. Again, this is due to my lack of understanding of how programming works... I just don't understand how it runs through the code... does programs run through the compiled code every 0.01 seconds? If that is true, I can just place a if-then statement to run functions... but I don't see how that is effective for CPU usage... so I disregarded that thought.
A function is only executed if it is called. It doesn't run every 0.01 seconds, unless you have a periodic event that calls your function. Yes, you are right on this one, it will be quite wasteful on CPU usage. When a function is called, the lines in it are run in sequence, top to bottom.
To have a function that only runs its contents if it is true, I believe it's as simple as using a return statement.
When a function is called, a "thread" is created. The return statement tells a function to terminate a "thread" and return to its caller. In the example above, if he conditions are not met, the function will return and ignore the actions. Forgive me for any confusion.. i really suck at understanding questions and explaining stuffl. ><
No problem FuzzYD. I'm still quite new to programming so pardon my lack of knowledge within this field.
Exactly what I'm confused about!
"void" from my understanding means there is no return type? So the code runs from top to bottom and sees the code in your post... Let's say when it ran through the conditions are not met and it skips out of the function... what if the conditions are met after running the function? I understand when we actually script this that it will run when the conditions are met, but I can't comprehend how it works! If the entire code file is only ran once from top to bottom, how does it check the condition when it is indeed true?
Thanks for the continuous support.
No probs mate. Yeap, void means no return type, thus we "return;" if we want to skip remaining actions. "return true;" would instead be used if the function was a bool type.
I don't think it's entirely correct to say that the entire code is run only once from top to bottom. When we finish programming our functions we "Compile" them. Once compiled you could say the functions are stored into the PC's memory whenever we load the map to be called later. Here's how I understand it... If I'm wrong I do encourage someone to come along and correct me.
Whenever an event fires and triggers a function, only that function will run once from top to bottom. If I type -test, a thread will be created for Function A, once it finishes its run, it will return to main() (though im not too sure what main() is in galaxy >_>) When a function is called, it will always execute/check only what is within its curly braces { } Function B will create a thread every 1 second and check conditions inside it.
So every time a function is run/called, it will recheck the conditions inside it.
To have a code that is called once but continuously checks for conditions to run actions, I would do this:
Whenever you use a wait, any other function that is queued in the processor will have a chance to run.
Thanks for clearing up most of the aspects of how it works.
Considering only the functions... Concerning the actual conditions for Function A, B and C. Wouldn't the program have to run whatever is inside the curly braces for every single function every time any action is done to check for any conditions that matches with the action?
For example: Function A - When I type "-test" Function B - When I type "-test2" Funciton C - When I move unit X
Be it a similar or completely different function, each function must be ran first to check for the conditions... because condition checks are within curly braces.
And what if you have a void function which checks for these conditions but you don't want it to be ran when triggered, only when you call on it (while conditions are true)? How does it differentiate? I think my questions are now deviating from SC2 and more into actual Galaxy or just programming as a whole, sorry about that.
Considering "Whenever an event fires and triggers a function"... This is exactly what I'm confused about... if you need a function that checks for a condition to run a function... and another function to run that previous function... its sort of like a endless loop of logic. That "event" is ultimately another function right? Just like how in GUI many of the presets or special data types are actually just strings.
Lets see if we can shed some light on the subject.
It is true that Events are basically functions (but a certain kind of functions. More about that below), and that there is some kind of endless loop in the fact that you need a function to call a function.
If you think about it - it's stange that anything actually works in a map since you have no starting point.
However, there is one function in every map which is executed once the map starts. You don't have to call it yourself. The function is called InitMap().
Since you've been working with Java and C you might have noticed that basically every program has a main() function. InitMap() serves the same purpose.
That's how it looks like:
It calls several different functions that basically initialize the map. For example in InitTriggers() all the GUI triggers are created and linked to events.
InitCustomScript is of particular importance when you're scripting. You can order this function to run some of your own functions and thus get your map rolling.
You can't, however, change any of these functions by hand. You can set-up an initializer function in each of your custom script sections. These initializers will then automatically be called in InitTriggers().
So in there you could, for example, start some of your triggers or functions to spawn units, or do whatever.
Now, this isn't exactly true. Compilation turns our script into a different computer language that the game can understand. That process isn't of any particular interest to us.
Most of the functions that we don't write ourselfs are natives (all blue-colored functions are natives). Natives communicate with the game itself to do things. If we call the UnitKill native, then this function tells the game to kill a certain unit, so this process basically doesn't happen within our code. We just give the order.
All the events are natives too. They tell the game that it should run a certain function when something happens.
E.g. the TriggerAddEventUnitDied tells the game it should run the associated function if a certain unit died. Our Galaxy script itself can't find out whether a unit is dead or not, it always needs to communicate with the game itself.
The game is much more sophisticated than our primitive script and has no problems noticing when a unit dies, a timer runs out or the world explodes. It can then tell our triggers that a certain thing happened.
Our functions are stored in the computer's memory, but only when we start playing the map (=loading it) and not when we're compiling (=saving) it. But just because they're loaded into memory doesn't mean they're set in store, by the way. You can very conveniently add events on the run:
Very useful stuff. Just wanted to throw it in, since that's something you don't learn when using GUI.
What exactly do you mean by that? Of course you can run a function just like normal and make it check for conditions, but keep in mind that you can't use event responses (EventUnit(), EventPlayer(), etc) since there was no event starting the function. So you have to supply parameters for the function another way.
That's basically what the game is doing. The entire Sc2 (and most other games) is basically just one giant loop that runs over and over and over.
Keep in mind that the game does everything that happens in the game. So it indirectly causes all the events to happen.
So basically just everytime something happens that could be caught by an event the game checks it: Is there any event that is linked to that object? No? Then never mind. Yes? Then call the associated function.
Of course the game knows all the things that can trigger events, so it knows which to check and which not to.
s3rius, thanks! You answered my questions exactly as well as some extra nifty stuff.
How would I include the initializer function if I'm coding outside of SC2? Currently my setup is coding in Notepadplusplus with Andromeda syntax and then compiling with Andromeda which also injects my code into a specific map as an import.
Or is it reverse psychology for the sake of user-friendliness? What I mean is, that we write a initializer function that includes the functions or things done instead of the other way around. So we write a function that starts with "Init", it gets marked and included in InitTriggers() which will then be ran during map initialization (Is that right?). I think this is what the includer does in the GUI instead of having some marker within the function to tell it to be included by "InitXYZ" which is then generated during compilation as it suggests in the GUI.
Thats pretty neat, I'll be using this quite a lot. Concerning gt_SomeDeathTrigger, is the parameter limited to global triggers? If not, does everything else gets automatically included when I use function TriggerAddEventXYZ for any function I write? (In other words do I need to write anything else after adding the event within a function, other than the actual function that is ran when the event is triggered?)
Haha, sorry for the confusion. You already answered this by in the next paragraph by clearing up one of my misunderstandings of the how it worked. Thanks!
And FuzzyD, you've been a great help too. Thanks a bunch! :)
In Andromeda you can put code in a static block to have it run on initialization.
You don't need to worry about the InitMap() function with Andromeda - the only important thing is that the init map function calls the initialization for Andromeda, which will handle all of your code.
Trigger variables do not need to be global - once an event has been passed a trigger you can get rid of the trigger variable if you want - the only reason to keep the variable is if you will need it later on, for instance adding it to another event or something. In fact if you wanted to you could place the call to TriggerCreate() directly in an event binding.
@AzothHyjal: Go
Thanks AzothHyjal!
By the way, I tried searching online and researching, but what exactly are enrichments and what are they used for? Is it something like allocating some attributes/properties to a class?
Take a look at this thread: http://sc2mod.com/board/index.php?page=Thread&threadID=13
sc2mod is the home of Andromeda, it's a good place to ask questions specific to it.
Enrichments are basically a way to add functionality to a type. For example, if I had an enrichment on the type unit called "getHP," I could then use any unit variable name along with that enrichment to get its hp. For example:
Even though unit is not a class, the enrichment allows me to define some class like functionality for it, instead of a traditional C approach which would be the following:
Actually, you can use accessors in enrichments to emulate non-static fields.
For example,
You can also add in static fields/methods as well as normal methods via enrichments.
Vermore, it appears to me that you do not quite have a solid understanding computer programming. I would highly recommend a foundation based on C and C++ or Java before delving into Andromeda. Andromeda is really meant for those who are proficient in such programming languages, as well as Galaxy (which is really just C--). You will find plenty of information online on how C, C++, and Java work.
As AzothHyjal said, sc2mod.com is the home of Andromeda. There, you will find the full documentation, instructions for use, coding guidelines, etc... as well as forums for asking any Andromeda specific questions you may have. As I mentioned before, however, users are generally expected to be familiar with at least Galaxy and an object-oriented language such as C++ or Java.
Despite all my criticism, I applaud your efforts to go beyond the clumsy tools Blizzard has given us in their Galaxy Editor. I think that scripting is the way to go when making custom maps, as it is the most powerful and the most efficient, in the hands of a skilled programmer. You have a ways to go, and I wish you luck.
Thanks AzothHyjal and fernsauce, I recognize them from Java! Now I know what they are called... :s
@XPilot: Go Hello XPilot! Haha, thank you. My school doesn't provide computer science and I'm not in university yet so I never got the chance to learn it properly... When I started programming I just wrote programs by deducing how it works from examples, so my understanding and vocabulary are down in the pits. I'm currently watching lectures from Stanford and MIT to improve my foundation.
I kinda learned the same way you are learning now. Looking at examples and pulling them apart like a puzzle. Reverse engineering is the way to go :P You'll tend to learn some nifty tricks here and there simply from looking at codes other than your own.
If you're modifying the map script directly then you can use a static{} block like Azoth said. That one only works for Andromeda.
Otherwise you can just write one of your init functions in the InitMap or InitTriggers functions. You gotta include it manually then.
If you mean by the second paragraph that all functions that start with Init will get included - no. Name has nothing to do with it. I could also call it TieMyShoes().
No, triggers do not need to be global.
Dynamically creating triggers can sometimes be very useful. For example when you have a large RPG with a dozen heroes. Each of the hero uses a different set of triggers (e.g. for skills and stuff). No need to create triggers for heroes that no one has chosen.
A snippet that I've found very useful:
This is basically replacing what GUI calls Action definitions.
If I want to run a function with Waits in it, but don't want the parent function (the one that's calling it) to wait for it being executed then I can just pass the name of the function to this one. It creates a trigger, runs it and destroys it immedidately after. Nice, clean, great.
Well, comes time comes knowledge.
If you stick with learning Galaxy then you'll soon understand everything.
With regards to TriggerDestroy(t), I suppose its good practice to destroy all trigger variables after they are used? Or is galaxy smart enough to help us collect and dump garbage. I know this is a little off topic here but i'm wondering if there are any variable types that can potentially leak. In JASS it was points and units i believe, always had to null them after usage.