An Action Definition is a void-type function; it simply executes its contents and when the end is reached it stops.
Regarding threads:
I haven't checked it out, but if it is what I think it is you should be careful using it. Threads in Java for instance are used for workload distribution. Most commonly the workload is distributed across multiple CPUs; however, it can also affect the exection order of a sequential piece of code.
If you go "huh?" to what I just wrote, I suggest you don't mess with it until you've read some tutorials about it. :)
Set the return value to (None). There's no point for an Action Definition to return a value., that's what functions are for.
Actions can fail, that's what I used the return value for.
@ Kafoso
That's something I can understand at least, having been a proficient C/C programmer many years back - the knowledge has waned a bit though over these years :) (Hell, I used to write assembly! Intel and AT&T :P)
Either way, this isn't entirely true, since I can make an action normally return a variable anyway, so I wouldn't agree with it being void (Although I had already stumled upon removing the return value to make it work - it's rather annoying for error catching and debugging though.
The threads are completely neccesary, although perhaps I could also use SC2's queing system (the threads created need to do a certain action after a certain interval. Making them singlethreaded means they get executed in serial, rather than at the same time). I'm used to working with mutexes though, it won't pose any problems.
PS. From my current understanding of the editor, it seems to me that functions can only be used as parameters in actions, whereas actions can be called regardless. That is: triggering player is a function. While text message is an action.
1) New threads can't return values. That's pretty easily understandable, too. The old thread (that started the new one) continues without stopping and does not wait for the new thread to return a value (that's specifically what you want!). But the return value could only be returned after the new thread finished it's operations. At that point the old thread is already faaaar ahead.
2) The distinction between actions and functions is only made by the GUI. I don't really know why they did it. A lot of "actions", for example return something too. CreateUnit returns a unit group or IssueOrder returns a boolean. If you're using the raw script then they're just functions alltogether. In fact, custom script is very similar to C+ + (just without all the good jazz like OOP or pointers).
3) Yes, functions can only be used in actions. Often you'll want to call them in a Set Variable action to actually store the return value. Actions are the other way round. If I remember correctly they can not be called as parameters (some actions might have a dublicate of the same name which is a function..).
Great to hear you have some (if not a lot) understanding of it. One has to respond in a certain fashion, as most questions in here go "What is 2+2?" and many people suffer from a "Search-field-blindness" affliction.
On a side note: The return value in void-type functions (like the main-method in C) is just a flag to notify the Stack that a code fragment has completed and no more calculations will be needed immediately after, for that specific function. That doesn't count as a "return" in my book; the compiler should be able to recognize the end of a void-type function, as in Java. :P Well, that was off-topic.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
If I make a new action definition, return type boolean. Completely empty except for: return true.
This compiles fine.
However, if under the options I say: create thread.
It suddenly starts giving error (Script failed to compile: Expected a return value (See Trigger Editor for more details)).
I don't get it? Anyone have a clue?
Set the return value to (None). There's no point for an Action Definition to return a value., that's what functions are for.
@Siaon: Go
Regarding the return type: What Tolkfan said
An Action Definition is a void-type function; it simply executes its contents and when the end is reached it stops.
Regarding threads:
I haven't checked it out, but if it is what I think it is you should be careful using it. Threads in Java for instance are used for workload distribution. Most commonly the workload is distributed across multiple CPUs; however, it can also affect the exection order of a sequential piece of code. If you go "huh?" to what I just wrote, I suggest you don't mess with it until you've read some tutorials about it. :)
Actions can fail, that's what I used the return value for.
@ Kafoso
That's something I can understand at least, having been a proficient C/C programmer many years back - the knowledge has waned a bit though over these years :) (Hell, I used to write assembly! Intel and AT&T :P)
Either way, this isn't entirely true, since I can make an action normally return a variable anyway, so I wouldn't agree with it being void (Although I had already stumled upon removing the return value to make it work - it's rather annoying for error catching and debugging though.
The threads are completely neccesary, although perhaps I could also use SC2's queing system (the threads created need to do a certain action after a certain interval. Making them singlethreaded means they get executed in serial, rather than at the same time). I'm used to working with mutexes though, it won't pose any problems.
PS. From my current understanding of the editor, it seems to me that functions can only be used as parameters in actions, whereas actions can be called regardless. That is: triggering player is a function. While text message is an action.
Well,
1) New threads can't return values. That's pretty easily understandable, too. The old thread (that started the new one) continues without stopping and does not wait for the new thread to return a value (that's specifically what you want!). But the return value could only be returned after the new thread finished it's operations. At that point the old thread is already faaaar ahead.
2) The distinction between actions and functions is only made by the GUI. I don't really know why they did it. A lot of "actions", for example return something too. CreateUnit returns a unit group or IssueOrder returns a boolean. If you're using the raw script then they're just functions alltogether. In fact, custom script is very similar to C+ + (just without all the good jazz like OOP or pointers).
3) Yes, functions can only be used in actions. Often you'll want to call them in a Set Variable action to actually store the return value. Actions are the other way round. If I remember correctly they can not be called as parameters (some actions might have a dublicate of the same name which is a function..).
@s3rius: Go
I wrote the map to be a state engine, the return value is only vital for error reporting in those threads anyway.
I really need to stop improving it all the time and just f*cking release it already, haha :)
@Siaon: Go
Heh. Looking forward to see your map.
Great to hear you have some (if not a lot) understanding of it. One has to respond in a certain fashion, as most questions in here go "What is 2+2?" and many people suffer from a "Search-field-blindness" affliction.
On a side note: The return value in void-type functions (like the main-method in C) is just a flag to notify the Stack that a code fragment has completed and no more calculations will be needed immediately after, for that specific function. That doesn't count as a "return" in my book; the compiler should be able to recognize the end of a void-type function, as in Java. :P Well, that was off-topic.