Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
function AddDamagingEffect takes player owner, string modelpath, real x, real y, real damageps , real duration, real area, boolean affectallies returns unit
return AddDamagingEffectEx( owner, modelpath, "", "", x, y, damageps , 1, duration, area, affectallies )
endfunction
Now, this is a random function that i picked from jasscraft
The thing that i want it to be explained is the parts:
-player owner
-real x
-real y
-real damageps
etc...
how should i use them / set them / something like that?
those are called function arguments, they are threated as local variables(no need to destroy them, those are always only copies) and those are constructed when you call function
Lets have example:
JASS:
function myFunction takes integer i, unit u returns nothing
//some code
endfunction
function someother function ...
local unit u = CreateUnit(...)
local integer i = 5
call myFunction(i, u)
endfunction
so we have function that takes integer and unit as arguments, and when we want to call the function, we must provide such data types when calling in parenthesis - () in exact order, and the variables are created inside the function as copies of the values from the outer function call
if this is too technical(shouldnt be), let me know I will try harder
In GUI, everything that is clickable within some action(like Create X(clickable) Units(clickable) ...) are all function arguments
edit:
you know what, lets talk about return values as well
you most likely noticed that there is also returns <type>(in this case nothing), this is to determinate what should function return
(nothing in terms of takes nothing means that you always call the function as () and returns nothing means that you cant asign the function call to any variable, on this later)
Example:
JASS:
function myFunction takes nothing returns integer
return 5
endfunction
this function has no arguments(you call it like myFunction()) but returns integer, which means that you can have variable initialized to the "function call", which in reality means that you will set the value of the variable to the value that function is returning, if I did integer i = myFunction() the i would have value 5, because Im returning 5
You can have return statement even in function which returns nothing, this is generally good if you want to stop execution of some function, maybe some error(dividing by 0 for instance)
generally the syntax is return <some value that is valid for type>, where some value ... can even be another function call (return CreateUnit(...)), in case of nothing you just write return
those are called function arguments, they are threated as local variables(no need to destroy them, those are always only copies) and those are constructed when you call function
Lets have example:
JASS:
function myFunction takes integer i, unit u returns nothing
//some code
endfunction
function someother function ...
local unit u = CreateUnit(...)
local integer i = 5
call myFunction(i, u)
endfunction
so we have function that takes integer and unit as arguments, and when we want to call the function, we must provide such data types when calling in parenthesis - () in exact order, and the variables are created inside the function as copies of the values from the outer function call
if this is too technical(shouldnt be), let me know I will try harder
In GUI, everything that is clickable within some action(like Create X(clickable) Units(clickable) ...) are all function arguments
Basically i know what they are, the thing i would like to know is WHERE/WHEN should i set them
Like in te ex you said you make the myfunction (//some code >> what should go here)
Then you make another function and in this one you set the arguments and call the myfunction, why didn't do that in the my function??
I dont understand fully, but I think I got what you dont understand
You dont need to initialize the arguments to values, because they always will have some value, which is passed to them as the argument to function, so real x in your case will always be object of type real with some value
You can set them to something else too
And what the function does is it calls AddDamagingEffectEx, which returns unit, and then returns the unit that was returned by this function call and passes to the function variables, that were passed to the AddDamagingEffect function
I just need one more thing to know, where to assign those arguments ? And why did ypu call the myfunction later in another function, if you can generate a functioning example, it may help more
well, the function arguments are generated automatically, you cant "assign" them, you are basically assigning them when you call function, you dont need to worry about them inside the function, you are guaranteed that they will be there and valid(excluding when you call function with null argument, it is still valid but null is "no object")
You can change the value of the intial argument, thats because the arguments are treated as any other local variable, just pre-initialized and you will lose the value that was in there before you changed it if you dont save those to other variables
and because everything in Jass needs to be in function, you need function to call another function
The basic generated function looks something like:
JASS:
function Trig_triggerName_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_triggerName takes nothing returns nothing
set gg_trg_triggerName = CreateTrigger( )
call TriggerAddAction( gg_trg_triggerName, function Trig_triggerName_Actions )
endfunction
this is how empty GUI trigger called triggerName looks like when converted to custom text(Jass)
Every "Action" in GUI you make, goes to Trig_triggerName_Actions, and as you see its again function
function AddDamagingEffect takes player owner, string modelpath, real x, real y, real damageps , real duration, real area, boolean affectallies returns unit
return AddDamagingEffectEx( owner, modelpath, "", "", x, y, damageps , 1, duration, area, affectallies )
local player owner = GetOwningPlayer(GetSpellAbilityUnit())
local string modelpath = Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
local real x = 0.00
local real y = 0.00
local real damageps = 500.00
local real duration = 0.00
local real area = 250.00
local boolean affectallies = false
endfunction
I'm understanding more, one more thing..
The up script, ALONE, what will he do, if nothing, what to make him do something
it will most likely give you compiler errors, and even if not the code would not run, I forgot to say that return is last statement executed, anything after return will not run, thats why return is good for controlled execution
if you want to set those arguments, you just need another function and do something like:
dont forget that in GUI, all variables have udg_ prefix(variable called var is in reality udg_var)
calling function like that from GUI is not very recommended, because you cant guarantee that the function will be at the top of your function, unless you use JNGP and the library prefix for that, or you put the map to global map script(when you click on map in trigger editor)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.