| 03-01-2003, 06:09 PM | #1 |
I only understand that it's the same as "Skip Remaining Actions" in the GUI. But why does it do what it does? How do you define return? If you have something like: If x=2 then do set x = 3 else Return Would that end the entire code or just that function in the trigger? Also you can do Return (Statement) how does that work? Thanks alot guys, your a big help. |
| 03-01-2003, 09:06 PM | #2 | |||
Guest | Quote:
Return is a common syntax used in almost all programming langauges. It's basic function serves as an intentional end of a function excution(which some might consider bad programming practice), as well as return the result of a computation to the calling function. Quote:
It will end exactly where the Return is excuted. Further lines within the function are ignore. Quote:
As for what sort of values are returnable are usually dependent on the types allow my the language. But common types are integers, floats, string, character, pointers. Example, you got 2 functions. The first one is the callin function n the 2nd one is juz a simple add function. function CALLING_Function takes nothing returns nothing local integer udl_a // declare local variables local integer udl_b local integer udl_Result set udl_a = udg_User_Input_1 // get user input 1 set udl_b = udg_User_Input_2 // get user input 2 set udl_Result = ADD_function( a, b ) // call Add_function and // store the RETURNED value // in udl_Result ...................other statements.................. ...................other statements.................. // Do whatever thing with the RESULT, display or use it for // next decision making endfunction function ADD_function takes integer a, integer b returns integer return ( a + b ) // return the results of a + b endfunction Hope this sort of giving u some idea on the uses of RETURN. P.S thx for the webspace, will upload in a few days time : P o yeah check out http://jass.sourceforge.net too, it got a nice basic introduction to the JASS language. |
| 03-01-2003, 09:09 PM | #3 |
Guest | sorry for the terrible placements for the sample code @@.....not used to the spacin on this forum yet : P. |
| 03-03-2003, 12:37 AM | #4 | |
you can use [code] and then end it and it will format it the way you have it. 1 more question, Quote:
I still don't understand that, it returns it where? If a was 1 and b was 2, would it print 3 on the screen or something? |
| 03-03-2003, 01:11 AM | #5 |
If the function has a return type, you're usually returning the value to a variable, at least in most languages. |
| 03-03-2003, 01:25 AM | #6 | ||
Guest | Iv got an easy explanation for you Sample function: Quote:
In this you have the function main. It declares a local integer x, then assignes it to run the function example. Example is then run, as you can see it returns an integer, this means that you can only use the return statement for integers. a is assigned 1 and b is assigned 2 then there values are added (3) and returned. Now the return value of example is 3. This value is assigned to x. So if you return an expression (such as a+b) that is bascally the value of the function. Consider this: Quote:
output: 10 10 In this code the functions are self explanitory. What happens is that we assign x to example(5), this calculates to 5+5 because thats what we returned from example. then we printed a new line, then we directly printed the return value of example(5) so you can see that it evaluates to 10 (5+5). This might be a little confusing but read it a few times and it should help you. And by the way, skip remaining actions in gui is equivilent to just return; with no value. |
