1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. Units have been turned into heroes in our latest Icon Contest! Vote for the best icon set at the Icon Contest #18 Poll!
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Erm... I'm Kind Of A New JASS Triggerer, I Hope You'll Help Me Here...

Discussion in 'Triggers & Scripts' started by Miss_Foxy, Nov 25, 2010.

  1. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Erm, this is my first Trigger I tried to make using JASS, it's supposed to Kill a Unit right after it's Spawned.

    Code (vJASS):
    function Spawn_Kill takes nothing returns nothing
    call CreateUnit (hpea)
    // I'm trying to create a Peasant //
    call KillUnit (hpea)
    endfunction


    This doesn't seem to work, please help me someone...
     
    Last edited: Nov 25, 2010
  2. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Code (vJASS):

    function Spawn_Kill takes nothing returns nothing
        call KillUnit(CreateUnit(Player(0),'hpea',0.00,0.00,0.00))
    endfunction


    Would be something like that since you can instantly create and kill a unit in single line.
    Or:
    Code (vJASS):

    function Spawn_Kill takes nothing returns nothing
        set bj_lastCreatedUnit = CreateUnit(Player(0),'hpea',0.00,0.00,0.00)
        call KillUnit(bj_lastCreatedUnit)
    endfunction

    Now when creating a unit,you need to fill required arguments/parameters.
    In this case,first is which player should own the unit,then unit ID,the next are unit's X and Y where it's supposed to be created and last is it's facing.

    As you might have noticed,the owning player is Player(0). In JASS,player indexes have their value smaller by 1 than in GUI,which means this associates Player 1 in GUI.

    Also this is a very useful tool when working with JASS.
     
  3. Titanhex

    Titanhex

    Joined:
    Jul 26, 2008
    Messages:
    1,007
    Resources:
    2
    Maps:
    2
    Resources:
    2
    Think of it in rational terms.

    You tell the computer to destroy -A PEASANT- but not -THE PEASANT-

    We have to figure out a way to tell the computer to destroy the peasant we just created.

    bj_LastCreatedUnit is just a variable the game uses and that you too can use. It saves you time from making your own variables.

    You can save that unit to that variable, and then tell the game to kill that specific unit via the example shown.

    The other problem is of course you need to fill in the extra values asked for. Garfield has shown you what these values are. If you get a helper program, most of them will tell you the extra values needed.

    Hopefully this helps you get that much closer to making your own JASS stuff.
     
  4. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Thank you so much, I really hope I didn't trouble you both... +Reputation!
    I have another question though, about what Garfield1337 said:
    Erm... How about the 'Fly Heights' of the Units and stuff like animation of the unit, etc. Where do those go?
     
  5. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    You mus set those with other functions.
     
  6. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    This Is A Confusing Trigger I Wanted To Do . . .

    Erm... I have another question, I hope you people wouldn't mind:
    Code (vJASS):
    function Peasant_Eats_A_Tree takes nothing returns nothing
    // This Function Is Supposed To Kill A Peasant After He Eats A Tree With My 'Eat Tree' Spell //
    call CreateUnit (hpea)
    call ability (aeat)
    endfunction

    // I'm kind of confused around here, sorry. //
    Caster_UnitId takes nothing returns integer
    return 'hpea'
    call KillUnit
    endfunction
     


    Please help me somebody! I hardly know what I'm writing :/
     
  7. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Ummm...you should really read some tutorial - this is where i learned JASS from.
    Also about killing peasant after creating him,did you see the function i wrote?
    Code (vJASS):
    function Spawn_Kill takes nothing returns nothing
        call KillUnit(CreateUnit(Player(0),'hpea',0.00,0.00,0.00))
    endfunction


    Now it's a bit confusing what you're trying to achieve. You say that you want to kill peasant after he uses your Eat Tree ability - why you create peasant then?
    If you want to kill unit that uses Eat Tree ability,use trigger like this:
    Code (vJASS):
    function Condition takes nothing returns boolean
        return GetSpellAbilityId() == 'Aeat'
    endfunction

    function Actions takes nothing returns nothing
        call KillUnit(GetTriggerUnit())
    endfunction

    //===========================================================================
    function InitTrig_JASS_Trigger takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition(t,Condition(function Condition )
        call TriggerAddAction(t, function Actions)
        set t = null
    endfunction
     


    1 more thing,when adding comments in JASS,you only need 2 slashes ( // ) at the start the text. (You write 2 more at the end of your comment which is unnecessary)
    Write it like this:
    Code (vJASS):
    function Actions takes nothing returns nothing
        call KillUnit(GetTriggerUnit()) //This kills triggering unit :O
    endfunction
     
  8. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    I'm really sorry, I was just really confused at the trigger format, because it's the first time I'm doing JASS, I get lost easily when I read the tutorials so I thought I'd do it myself and see how I learn it:) Thanks.
    PS: Also, if I don't write the two slashes at the end, how do you set it so that you can 'tell' that it's ending?
     
  9. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Sorry about what? You're free to ask anything :D

    Anyway,the tutorial i gave link for is easy to follow. Also it's not easy to learn JASS without a tutorial or someone who would explain you how to write codes.
    And when typing comments: There's no need to 'tell' when it's ending because you can make whole line a comment or make a comment after calling some function.
    Example:
    Code (vJASS):

    function lolzor takes nothing returns nothing
        //this whole line is a comment
    endfunction

    function moar lolz takes nothing returns nothing
        call SomeFunc(blabla) //this comment lies after the function,so there's no need to mark it's end
    endfunction
     
  10. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,029
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    When you learn JASS, a few things you need to keep in mind:

    1. Conditions and Actions are almost the same thing. The differences between the two are unimportant for your level of JASS knowledge.

    2. Functions are the bread and butter of JASS. A function is comparable to a math equation (SquareRoot, Cos, Sin, etc.), because you can use it over and over for many different things.

    3. There are parameters, return-types and local variables in JASS which are nonexistent in GUI.

    4. Syntax errors! GUI does not have these, but they can help you find your mistakes.

    5. Endblocks...

    Code (vJASS):

    //Every
    function <name> takes nothing returns nothing
    //Must end with...
    endfunction
    //Every
    if (true) then
    // Must end with...
    endif
    //Every
    loop
    //Must end with...
    endloop
    //Every bracket or quote must end with a closing bracket or quote.
    ( )
    [ ]
    " "
    ' '
     


    Ask questions based on new information you've received, and you will receive more specific answers.
     
    Last edited: Nov 27, 2010
  11. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    After reading some guides, I still don't understand what it meant by:

    Code (vJASS):
    function Random takes nothing returns nothing
    // Well, I kind of don't understand what to put in the Returns and Takes tab,
    // Like, returns integer, etc. What do they do?
    endfunction


    Please do help me out, I'm really sorry for troubling anyone...
     
  12. Ironside

    Ironside

    Joined:
    Feb 3, 2009
    Messages:
    2,723
    Resources:
    4
    Maps:
    3
    Tutorials:
    1
    Resources:
    4
    The takes keyword is a value which the function needs, if we put

    Code (vJASS):

    function Random takes integer a returns nothing
    endfunction
     
    Now if we call the function, we need to parse a number to it, or it won't work properly:

    Code (vJASS):

    call Random(5)

    // or

    local integer number = 5
    call Random(number)
     
    If the function Random takes integer as we have above, and we try to call it without parsing the argument, we'd get a compile error:
    Code (vJASS):

    call Random() // will give a compiler error when saving!
     
    The return keyword is a value tha the function will return with the return command.

    Code (vJASS):

    function Random takes nothing returns integer
    return 5
    endfunction


    function Main takes nothing returns nothing
    local integer number = Random()
    endfunction
     


    And for the last I will provide a full example for takes and returns:

    The function will return a random number among the 1st argument and the 2nd argument.
    In this case a random number between 1 and 50.


    Code (vJASS):

    function Random takes integer n1, integer n2 returns integer
    local integer rnd = GetRandomInt(n1, n2)
    return rnd
    endfunction

    function Main takes nothing returns nothing
    local integer number = Random(1, 50)
    endfunction
     
     
  13. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Like mathematical functions.
    F(x) = y
    x is what it takes and y is what it returns.
     
  14. Ironside

    Ironside

    Joined:
    Feb 3, 2009
    Messages:
    2,723
    Resources:
    4
    Maps:
    3
    Tutorials:
    1
    Resources:
    4
    Hell he made 1 page into 3 lines :/ I really do make things complicated
     
  15. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Your explanation is better,of course. I just said it shorter.
     
  16. Ironside

    Ironside

    Joined:
    Feb 3, 2009
    Messages:
    2,723
    Resources:
    4
    Maps:
    3
    Tutorials:
    1
    Resources:
    4
    I do think yours is enough, mine is just if he needs a fresh example of it.
     
  17. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Let's take the mathematical function that was mentioned earlier and modify it a little: ƒ(x) = x²

    Clearly what the function ƒ does in this situation is take a parameter "x" and square it. Notice that the value returned could be a decimal point number - in Warcraft III the type associated with this is a
    real
    , so let's make this function in JASS:

    Code (vJASS):
    function F takes real x returns real // I will explain further
        return x*x;
    endfunction


    In function ƒ you've got a single parameter "x". Notice how when we define a "parameter" (in this situation the parameter is
    real x
    ) that there is a type
    real
    and a label
    x
    . The label or "name" of the parameter allows you to reference it throughout the function. In function ƒ we give it the name "x" and reference it as "x" in the function. Multiple parameters must be separated by a comma.

    Also notice that the return parameter does not have a name. Think of the name of the return as the name of the function; it gives a "type" value to the function. In the case above of function ƒ the name of the function is "ƒ" and the type would be a
    real
    (as shown by the return). This is very important information because when you reference a function as a value you need to think about the type of the function.

    Let's use this in a more elaborate example.

    Code (vJASS):
    function F takes real x, real y returns real
        return x*x + y*y;
    endfunction

    function DoMath takes nothing returns nothing
        local real array pointX
        local real array pointY
        local real distance

        set pointX[0] = 50
        set pointY[0] = 80 // yields point (50, 80)

        set pointX[1] = -800
        set pointY[1] = -70 // yields point (-800, -70)

        // Notice how the variable "distance" has been
        // defined of type "real". This means that we need
        // to use real values to associate with it.

        set distance = SquareRoot( F(pointX[0]-pointX[1], pointY[0]-pointY[1]) )

        // The parameters being given to function "F" are
        // shown above. The "x" parameter would be satisfied
        // as "pointX[0]-pointX[1]" and the "y" parameter
        // would be satisfied as "pointY[0]-pointY[1]".

        // This example (function F) will sum the squares of
        // the "x" and "y" parameters; once these operations
        // have been performed a value of type "real" will be
        // returned - this value will then be assigned to the
        // reference named "distance".

    endfunction


    I hope this helped without saying too much that has already been said.
     
  18. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    It's confusing, but I'll try to get it, thanks:)
    Erm, there's another question if you guys wouldn't mind though:

    Code (vJASS):
    function Unit_Enters_Region takes nothing returns nothing
    call CreateUnit
    // I'm actually quite stuck here, how do you make an event (Any event would do) which happens when a unit enters a region?
    endfunction


    I hope you guys wouldn't mind...

    PS: What are 'reals' ?
     
  19. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    You can do it like this. I'm using playable map area as the region.

    Code (vJASS):
    private function InitTrig_SomeTrigger takes nothing returns nothing
            local region mapArea = CreateRegion()
            local trigger t3 = CreateTrigger()
           
            call RegionAddRect( mapArea , bj_mapInitialPlayableArea )
            call TriggerAddAction( t3 , function SomeFunction )
            call TriggerRegisterEnterRegion( t3 , mapArea , null )
        endfunction


    Integers = 1 , 5 , 100 ...
    Reals = 1.15 , 1.1 , 3.668 ...
     
  20. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Above the rect
    bj_mapInitialPlayableArea
    is being added to the region
    mapArea
    so that the trigger-event can be registered. This is necessary as there are no natives that allow events to be registered using rects.

    The final step is to add an action to the trigger with the registered event so that when the registered event occurs your designated function (in this case
    function SomeFunction
    ) will be executed and from there you can use event responses to reference associated handles.

    Good luck.