my first jassing ;]

ironfist19

New Member
Reaction score
3
Hello this is my first code :D , i didn't convert it... just looked at some things ;]
btw i am beginner in jass i just converted from gui to jass yesterday ;]

JASS:

function Trig_Practice_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc(1,'hfoo', Player (0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING)
endfunction

//===========================================================================
function InitTrig_Practice takes nothing returns nothing
    set gg_trg_Practice = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent ( gg_trg_Practice , Player (0) , "-create" , true )
    call TriggerAddAction( gg_trg_Practice, function Trig_Practice_Actions )
endfunction


can you guys give me a practice? like link to practicing jass...
 

ironfist19

New Member
Reaction score
3
I have a question : What does return do? I don't understand this :
JASS:
function Trigger_1 takes nothing returns nothing

Some say that "takes" takes the parametertype but what does it actually do?
and "returns" returns a value.. I don't understand :/ can somebody explain it to me and what does it do?
ex.
JASS:
function adding takes integer a returns integer
return a = a + 1
endfunction

^ what does this actually do?
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
JASS:

    function adding takes integer a returns integer
        return a = a + 1 <<WRONG
    endfunction
//Takes integer, this means when you will call this, you will need to add an integer,
//returns integer, must return an integer, if you sa a + 1 to false or true, thats wrong, that returns boolean
    function adding takes integer a returns integer
        return a + 1 <<CORRECT
    endfunction

    function InitTrig_Add takes nothing returns nothing
        call SetHeroLevel(ThisHero,adding(5),true)
        Will set hero level to 6.
    endfunction
 

Komaqtion

You can change this now in User CP.
Reaction score
469
6 ;)

The "return" keyword in Jass makes a function able to be used as any other variable or so of that type, like if a function takes an integer (Like the "adding" function above) then, when calling that function, you can either use a variable with the type "integer", a straight on integer (like "5" XD) or a function which returns an integer ;)

You understand? :S
 

ironfist19

New Member
Reaction score
3
Uhmm I understand a lil bit... but can you give other examples?
6 ;)

The "return" keyword in Jass makes a function able to be used as any other variable or so of that type, like if a function takes an integer (Like the "adding" function above) then, when calling that function, you can either use a variable with the type "integer", a straight on integer (like "5" XD) or a function which returns an integer ;)

You understand? :S
 

Komaqtion

You can change this now in User CP.
Reaction score
469
JASS:
function AddInt takes integer i returns integer
    // This function will need an integer variable
    // (In this case it's the "integer i" which is inputted when calling the function)
    // which it will add a value to (In this case 1) and that is what it can be used for,
    // if you need some integer directly, to get 1 greater, just use this <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
    // (DO NOT TAKE THAT AS ADVICE, YOU SHOULD SIMPLY USE set i = i + 1 INSTEAD <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />)
    
    return i + 1
endfunction

function Actions takes nothing returns nothing
    local integer int = 0
    // This is the variable we&#039;re gonna use with the above function <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" /> (Doesn&#039;t have to be a variable, you could just do like this:
    // call AddInt(0)
    // But then you can&#039;t use the returned value...
    
    // You could also just do this instead of the stuff below:
    // call BJDebugMsg( I2S( AddInt(0) ) )
    
    set int = AddInt(int)
    
    call BJDebugMsg( I2S( int ) )
    
    // What will this display ? A little question for you <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
    
    // Btw, this is how you SHOULD do it instead of this example:
    // set int = int + 1
endfunction

function InitTrig_Takes_and_Return_Tut takes nothing returns nothing
    set gg_trg_Takes_and_Return_Tut = CreateTrigger()
    
    call TriggerRegisterTimerEvent( gg_trg_Takes_and_Return_Tut, 1., true )
    
    call TriggerAddAction( gg_trg_Takes_and_Return_Tut, function Actions )
endfunction
 

BlueMirage

Trust, but doubt.
Reaction score
39
I like to think of return as the Y value of a function in a coordinate system. X is the value one puts in, which in this coding language is "takes".
You know what a variable is right?
If something returns a value, you can set a variable to that type of value. Example:

JASS:
function something takes nothing returns nothing
    local location NAME //We create a location variable, or a point as it is called in GUI
    set NAME = GetUnitLoc(Someunit)
endfunction


We can think of GetUnitLoc() as a function of a graph.
However, unlike the function you created (Add), it does not "take" an integer as a parameter.
It takes a unit. Nor does it "return" an integer, it doesn't even return a unit! It returns a location,
or a GUI point, something completely different from what we put into the function, which was a unit.

I hope that made some sense. First time I'm trying to explain JASS to someone.
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
Take as example if you have a machine that makes cakes from you, then you have something that expects to take for example 3 ingredients (call them ingredient1 up to ingredient3) and will return you cake. Then you have something that looks like this in Jass:

JASS:
function MakeCake takes ingredient1 i1, ingredient2 i2, ingredient3 i3 returns Cake
  //Process on how to make a cake here.
  return aProcessedCake
endfunction


And now everytime you have some ingredients you need to call this function and provide it the ingredients and it will give you cake in return.

So for example

JASS:
set someCake = MakeCake(someIngredient1, someIngredient2, someIngredient3)
call EatCake(someCake) //Note that the EatCake function is probably not going to return anything except maybe some crumbs.


As a last note: The difference between programming and this example is that in general the things a function take are generally not "consumed" so once you have the ingredients to make one cake, you can make an infinite amount of cakes ... if only ... .
 

Komaqtion

You can change this now in User CP.
Reaction score
469
No, that will not work...
As the "take" variable "u" isn't a global, meaning it'll only work in the function it's declared and used.
But, you can simply make a global block like this, and then do that (Though you need to rename the function "KillUnit" as it interfers with the native [ljass]KillUnit[/ljass] ;))

And for the "link to all the call function", just get Jass NewGen Pack ! :D

It's stickied here at the forum (Though the regular WE Help forum) and it has a small integrated thing called TESH, which has a list of all the natives and BJs :D
 

BlueMirage

Trust, but doubt.
Reaction score
39
It will work if "u" is a global unit variable, and if you do the two in order. Example:

JASS:
function somefunc takes nothing returns nothing
    call TakeUnit
    call KillUnit
endfunction


However, do note that you can't use KillUnit as a function name. It's already the name of a native function :p
 

ironfist19

New Member
Reaction score
3
Ok...

What is jass newgen pack? ;]

No, that will not work...
As the "take" variable "u" isn't a global, meaning it'll only work in the function it's declared and used.
But, you can simply make a global block like this, and then do that (Though you need to rename the function "KillUnit" as it interfers with the native [ljass]KillUnit[/ljass] ;))

And for the "link to all the call function", just get Jass NewGen Pack ! :D

It's stickied here at the forum (Though the regular WE Help forum) and it has a small integrated thing called TESH, which has a list of all the natives and BJs :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top