• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Need Some Explenations...

Status
Not open for further replies.
Level 16
Joined
Jul 31, 2012
Messages
2,217
JASS:
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? :ogre_rage:
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
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??
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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

if this still didnt helped, let me know
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
JASS:
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
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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:

JASS:
function someFunction takes nothing returns nothing
    call AddDamagingEffect(GetOwningPlayer(GetSpellAbilityUnit()), "Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl", 0.00, 0.00, 500.00, 0.00, 250.00, false)
endfunction

or do something like you did but inside other function

this is equivalent of doing:
  • someGUITrigger
    • Events
    • Conditions
    • Actions
      • Custom script: call AddDamagingEffect(your variables)
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)
 
Status
Not open for further replies.
Top