| 11-10-2008, 02:34 AM | #1 |
Hi. I've recently started learning about map-making and as I want to include a particle system into my map I need to learn how to use JASS. I was reading the tutorials while are mostly extremely helpful. Vexorians in particular helped me understand a lot and I feel I am starting to grasp it. There is one point in his tutorial where I got lost. The part about function's taking and returning. I'm still unsure when it is necessary to take and return and what their usess are. For example, mid way through the tutorial he started using a function 'Msg' to shortcut a function to message player 1 (or 0 in JASS xD). EDIT: Oops it is later he specifies Player 1, still.... JASS:function Msg takes string s returns nothing call DisplayTextToForce( GetPlayersAll(), s ) endfunction function ShowMessage takes nothing returns nothing call Msg("This is a message!") endfunction function ShowSum takes integer a, integer b returns nothing local integer r=a+b call Msg("r= "+I2S(r)) endfunction function Trig_JASS_test_Actions takes nothing returns nothing call ShowMessage() call ShowSum(33,45) endfunction Now why does function Msg take String s and where does String s go as I don't see it used anywhere else. Would be good if someone could explain and also I apologise if this is the wrong place to post. Thanks. |
| 11-10-2008, 02:40 PM | #2 | |
Quote:
|
| 11-12-2008, 08:42 AM | #3 |
Ahh I think I understand. A sort of way to streamline your code? Are there limits to when a function must/must not use arguments or is it solely for when the user needs to use them? So a return is like the opposite, it sets a variable? |
| 11-12-2008, 10:00 AM | #4 | ||
Quote:
Quote:
JASS:globals region reg unit un endglobals function Foo takes unit u, real x, real y returns boolean call SetUnitX(u, x) call SetUnitY(u, y) return IsUnitInRegion(reg, u) endfunction function Bar takes nothing returns nothing local boolean b call Foo(un, GetUnitX(un)+100.0, GetUnitY(un)+100.0) //we just call the function, not caring about the return value set b = Foo(u, GetUnitX(unit)+100.0, GetUnitY(unit)+100.0) //we also get the function's return value and store it to b if b then call BJDebugMsg("Unit in region") endif //we can also use it directly wherever we could use a boolean if Foo(un, GetUnitX(un)+100.0, GetUnitY(un)+100.0) then call BJDebugMsg("Unit in region") endif endfunction |
