I'm just getting into some more complex triggering stuff, and I noticed that there is a predefined "Return" action, but how do I use it? I think I have to use a function in this case?
The context in which I want to use it is that I implemented an Action Definition (as a Thread) which is applied to single units and should give them commands in a specific time window (something like 2-10s, not sure yet, see the "Multithreading and AI" tutorial for reference). That part is working as I want it to be (individual orders for different units which are applied periodically), but my problem is that I want to use quite a lot of different unit states for different unit actions and it would be really nice if I could write them into triggers outside of the original Action Definition (even if its just to get a clearer arrangement of everything, especially as I want to run different actions for different unit types), but I have to be able return values afterwards and save them into Variables in the Action Definition (to switch between the unit states). Is that possible?
It should be Action Definition -> Runs Trigger/Function XY -> Trigger/Function XY Returns Value Z -> Saves Value Z into Local Variable A in Action Definition
Do I have to work with functions instead of triggers in this case? What is the difference between functions and triggers in the Galaxy Editor anyway? How do I use functions here?
Sorry if these questions have been answered before, I hope they are not too annoying and you can help me :) I'm not very experienced with the Galaxy language and it doesn't really help that there is a whole lot of predefined functions that you don't know where to start and what you are allowed to do and what you aren't allowed to do.
Thanks for responding this fast :) And how do I call functions? Thats my main problem right now.
edit:
Oh, I got it, its made directly by setting the variable. That makes sense.
So functions ALWAYS return values in galaxy? Or how do I call them else?
Functions return something. Action definitions won't return anything. That's the difference between those 2 types.
Triggers can be started by an event and have their own thread. Everything always starts in a trigger with an event.
You can then call functions and action definitions to execute the specified code everywhere and give parameters to adjust what they will do.
If you make them threaded inside their settings, you can pass for example a unit to them and with a loop (like: while(unit is alive) -> check orders; wait 4 ingame seconds ), you could create 1 thread per unit that stops, if the unit dies. You can't do that with triggers directly because you can't pass local variables to triggers, however, you can pass variables to functions and action definitions.
As an example for a function, you can create a function that returns a unit type for a specified integer which could be the current level in a tower defence. So you can make 1 spawn trigger which calls the correct units for the current level.
In functions, you need to make sure that every program's path returns something at its end. While returning the value, the program exits the function.
Most of the stuff I code uses mostly functions and actions definitions and only a few triggers which contain different events.
Hey guys,
I'm just getting into some more complex triggering stuff, and I noticed that there is a predefined "Return" action, but how do I use it? I think I have to use a function in this case? The context in which I want to use it is that I implemented an Action Definition (as a Thread) which is applied to single units and should give them commands in a specific time window (something like 2-10s, not sure yet, see the "Multithreading and AI" tutorial for reference). That part is working as I want it to be (individual orders for different units which are applied periodically), but my problem is that I want to use quite a lot of different unit states for different unit actions and it would be really nice if I could write them into triggers outside of the original Action Definition (even if its just to get a clearer arrangement of everything, especially as I want to run different actions for different unit types), but I have to be able return values afterwards and save them into Variables in the Action Definition (to switch between the unit states). Is that possible?
It should be Action Definition -> Runs Trigger/Function XY -> Trigger/Function XY Returns Value Z -> Saves Value Z into Local Variable A in Action Definition
Do I have to work with functions instead of triggers in this case? What is the difference between functions and triggers in the Galaxy Editor anyway? How do I use functions here?
Sorry if these questions have been answered before, I hope they are not too annoying and you can help me :) I'm not very experienced with the Galaxy language and it doesn't really help that there is a whole lot of predefined functions that you don't know where to start and what you are allowed to do and what you aren't allowed to do.
@Bommes: Go
functions return values .....
actions do things when you don't want a response back in the code that ran the function....
generally they are the same thing ..... but I separate them like this for organizational sake
@SouLCarveRR: Go
Thanks for responding this fast :) And how do I call functions? Thats my main problem right now.
edit: Oh, I got it, its made directly by setting the variable. That makes sense. So functions ALWAYS return values in galaxy? Or how do I call them else?
Functions return something. Action definitions won't return anything. That's the difference between those 2 types.
Triggers can be started by an event and have their own thread. Everything always starts in a trigger with an event.
You can then call functions and action definitions to execute the specified code everywhere and give parameters to adjust what they will do.
If you make them threaded inside their settings, you can pass for example a unit to them and with a loop (like: while(unit is alive) -> check orders; wait 4 ingame seconds ), you could create 1 thread per unit that stops, if the unit dies. You can't do that with triggers directly because you can't pass local variables to triggers, however, you can pass variables to functions and action definitions.
As an example for a function, you can create a function that returns a unit type for a specified integer which could be the current level in a tower defence. So you can make 1 spawn trigger which calls the correct units for the current level.
In functions, you need to make sure that every program's path returns something at its end. While returning the value, the program exits the function.
Most of the stuff I code uses mostly functions and actions definitions and only a few triggers which contain different events.
@Ahli634: Go
Thanks, this helps a lot! I think I figured it out now, I did a quick test and as far as I can tell everything is doing what it should do.
The main usage of Action Definitions & Functions if no direct events are involved seems natural and I'll probably try it like that. Thanks again!