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. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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] Few Questions

Discussion in 'Triggers & Scripts' started by kennyman94, Mar 16, 2010.

  1. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    Hi. I'm learning to use Jass and have read all the tutorials i could find and still have many questions especially about triggers.
    Lets say you have a trigger assisted spell called portal. the ability is based off of Archimond's Dark Portal spell and summons nothing. The unit is based off of the human campaign 'portal' and has the Waygate ability. The trigger's actions would be:
    • set tempPoint[1] to position of (casting unit)
    • set temppoint[2] to target point of ability being cast
    • create 1 Portal at tempPoint[1] for (owner of (casting unit))
    • set Waygate destination for (last created unit) to tempPoint[2]
    • create 1 portal at tempPoint[2] for (owner of (casting unit))
    • set Waygate destination for (last created unit) to tempPoint[1]
    • custom script: call RemoveLocation(udg_tempPoint[1])
    • custom script: call RemoveLocation(udg_tempPoint[2])


    When converted to custom text and simplified the trigger would look something like:

    Code (vJASS):
    function PortalConditions takes nothing returns boolean
        return GetAbilityID()=='A000'
    endfunction

    function PortalActions takes nothing returns nothing
        local location loc1=GetUnitLocation(caster)
        local location loc2=GetSpellTargetLocation()
        local unit portal1= CreateNUnits(1, loc1, GetUnitOwner(caster))
        local unit portal2= CreateNUnits(1, loc2, GetUnitOwner(caster))
            SetWaygateDestinationBJ (portal1, loc2)
            SetWaygateDestinationBJ (portal2, loc1)
            call RemoveLocation(loc1)
            call RemoveLocation(loc2)
            set portal1 = null
            set portal2 = null
    endfunction

    //======================================

    function InitTrig_Portal takes nothing returns nothing
        set gg_trg_Portal = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(gg_trg_Portal, EVENT_UNIT_ABILITY_CAST)
        TriggerAddCondition(gg_trg_Portal, condition(PortalConditions),
        TriggerAddAction(gg_trg_Portal, PortalActions)

    *not exact functions

    Do the actions and conditions need in a special place like when you click on the map name in the trigger editor, above the area where the actions/conditions/events are displayed, and to the left, where it says 'code entered here will be loaded after global variables and before any other functions? (i hope you got that) and does there need to be a function that starts at melee initialization in order to call the InitTrig_Portal function to actually make the trigger?
    ill finish this post when im able
     
  2. Ironside

    Ironside

    Joined:
    Feb 3, 2009
    Messages:
    2,723
    Resources:
    4
    Maps:
    3
    Tutorials:
    1
    Resources:
    4
    Code (vJASS):

    function InitTrig_Portal takes nothing returns nothing
        set gg_trg_Portal = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(gg_trg_Portal, EVENT_UNIT_ABILITY_CAST)
        TriggerAddCondition(gg_trg_Portal, condition(PortalConditions),
        TriggerAddAction(gg_trg_Portal, PortalActions)
    Well.. this above is the initilization function of a trigger... In here is set on what event the trigger runs and sets a function for the conditions and actions (if any)

    Code (vJASS):
      set gg_trg_Portal = CreateTrigger()
    This line creates your trigger for use.

    Code (vJASS):
     TriggerRegisterAnyUnitEventBJ(gg_trg_Portal, EVENT_UNIT_ABILITY_CAST)
    This is the function that sets on what event to run.

    Code (vJASS):

     TriggerAddCondition(gg_trg_Portal, condition(PortalConditions)
    This code is to set the function of the conditions, in your case PortalConditions.


    Code (vJASS):
     TriggerAddAction(gg_trg_Portal, PortalActions)
    This code is to set the function of the actions, in your case PortalActions.
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    The world editor basically reads this code from up to down. The triggers that come first are the ones placed first. When you refer to functions, you must refer to a function above the action.

    Example:
    Code (vJASS):
    //This would compile without any errors
    function Whee takes nothing returns nothing
    endfunction

    function Argh takes nothing returns nothing
        call Whee()
    endfunction

    Code (vJASS):
    //This would cause an error.
    //Undefined function Argh()
    function Whee takes nothing returns nothing
        call Argh()
    endfunction

    function Argh takes nothing returns nothing
    endfunction


    (Unless you use:
    ExecuteFunc("Argh")
    )

    Functions in the header are sent immediately to the top of the script, so they are parsed first. This allows them to be used globally. You can use functions globally if they are in a trigger, but the trigger must be before all the others. (Unless you use vJASS)

    When you add the InitTrig_ prefix, it will automatically be ran. There is no need to run the function, it will do that at the start of the map automatically. All the functions with an InitTrig_ prefix are sent to the top of the map to be called from a function called "InitCustomTriggers". This function is ran immediately upon map initialization so no need to worry about calling it separately.
     
  4. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    THANK YOU SOOO MUCH!! I was having so much trouble trying to figure out what actually causes the function that creates the trigger to run. That explains so much. I mean this kind of stuff really should be mentioned in the tutorials.

    Thank you but i already understood that part. What I dont understand is whether or not it matters if the -Actions function comes first or the
    -Conditions function does.
    I also want to know if it matters whether you need to have TriggerAddCondition come before TriggerAddAction or if they can be switched.

    has anyone made a post that lists all of the premade functions and the paramaters in proper order and what it does or correlates to in gui and if it is a native or bj and (if it is a bj) whether it is effective or inefficient and if inefficient recommends a good replacement?
     
    Last edited: Mar 17, 2010
  5. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    It makes no difference, as long as they are above the
    InitTrig
    function (so that they can be "seen" when referenced). You could also just use JNGP and declare scopes, in which case you can declare your own initialization functions.

    Just never use BJ functions. Again, if you use JNGP then there is a really easy-to-use Function List which shows what exactly the functions do (and you can use these to formulate your own methods). If you don't have JNGP, then you could always open up war3.mpq, look for "scripts", and inside that folder is a file called blizzard.j and common.j, both of which have a list of the function APIs.
     
  6. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    first, what are scopes?
    second, where is this functions list? because i do have jngp.
     
  7. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Scopes define where a certain object can be "seen". Read the JassHelper Manual (in the jassnewgenpack folder).

    The functions list appears in TESH (the syntax highlighter) --do you have that?
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,036
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    There is a library or "lookup" button when you're editing the code in NewGen. Use that library to look up a *ton* of functions.

    A scope gives you greater control over your JASS code. Normally, if you want a function in each trigger called Actions, that's impossible, because you can only have one of a function name. Just, when you have a function in a scope, 99% of the time you want to write
    private function
    instead of
    function


    A scope allows you do create functions called Actions in a bountiful number.

    Code (vJASS):
    scope Name_Of_Scope initializer Actions
        private function Actions takes nothing returns nothing
        endfunction
    endscope
     
    scope Another_Name_Of_Scope initializer Actions
        private function Actions takes nothing returns nothing
        endfunction
    endscope
     
  9. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    I was told that tesh is horribly broken.

    What are structs and how do they work?

    So, scopes can contain multiple functions? and can you explain the syntax for the scope? like what is INITIALIZER and is actions the equivalent of InitTrig_ since it is after Initializer?

    so could you have something like this?

    Code (vJASS):
    scope Portal initializer portal
        private function conditions takes nothing returns boolean
            //conditional statement
        endfunction

        private function actions takes nothing returns nothing
            //actions
        endfunction

        private function portal takes nothing returns nothing
            set gg_trg_Portal = CreateTrigger()
            call TriggerAddActions //blah blah blah
            call TriggerAddConditions // blah blah blah
        endfunction
    endscope

    scope IncomeIncrease initializer income
        private function conditions takes nothing returns boolean
            //conditional statement
        endfunction

        private function actions takes nothing returns nothing
            //actions
        endfunction

        private function income takes nothing returns nothing
            set gg_trg_Portal = CreateTrigger()
            call TriggerAddActions //blah blah blah
            call TriggerAddConditions // blah blah blah
        endfunction
    endscope
     
  10. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    TESH works fine, it just doesn't highlight the Hashtable API and its syntax checker isn't functional. (it doesn't parse vJASS, but you don't really need the syntax checker if you have JNGP. TESH runs using the old pJASS syntax highlighter I think, or at least some version of it)

    http://www.hiveworkshop.com/forums/1508879-post11.html
    I'm too lazy to rewrite it. =P


    Yes, scopes can contain multiple functions. Scopes are pretty much nothing but a kind of container. They "contain" your functions, in reality scopes are nothing but commented lines. =P However, they allow you to use the prefixes private and public for your functions to prevent function naming collisions and for general encapsulation. initializer are the equivalent of InitTrig_. Basically, you'll declare an initializer like this:
    Code (vJASS):
    scope Whee initializer Argh
    private function Argh takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        //add condition func, add action func etc.
        set t = null
    endfunction
    endscope

    It is essentially the same as:
    Code (vJASS):
    function InitTrig_Whee takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        //add condition func, add action func etc.
        set t = null
    endfunction


    If the trigger's name is Whee.

    Yep =)
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,036
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Seconded.

    There is nothing wrong with the scopes you created. You're a faster learner than I was with that, since my initial reaction was zomg I thought all lines start with function what do I doooooooo.

    Or something similar.

    Have fun!
     
  12. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Look at the JassHelper manual (link in my signature) for all of the available features of JassHelper.

    Not only can you declare functions within scopes, but you can declare other things as well. Anything declared within a scope can be privatized, or publicized, depending on where you want each "object" to be able to be referenced from.

    Libraries work exactly like scopes, except libraries can require other libraries (allowing them to be ordered, unlike scopes). This is the fundamental difference between the two. The manual is actually pretty well written, and it provides lots of good examples to help you understand vJass/JassHelper syntax.
     
  13. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    Thank you guys. (and hi im back again)
     
  14. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    Wait, so you can also declare variables like locals within a scope even if it is not in a function? Also aren't locals actually used bfunctions other than the one they are declared in when you use them as a paramater when calling a function? Because people keep saying a local can't be used by any other function than the one they are declared in.

    What is the difference between a function and a public function?

    What do you mean by a library can require another library?

    What is MUI?
     
    Last edited: Apr 21, 2010
  15. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    You can never declare local variables outside of a function. If you want a variable that can be referenced inside the scope, then make a global. It doesn't make any sense to have a "local" variable outside of a function, there is nothing to be local to. If you pass a local variable as a parameter then those passed variables become local to the function that is taking them.

    Public functions within different scopes can share the same name, but basically it just adds an "invisible"
    ScopeName_
    prefix to the function. Normal functions are referenced exactly as they are declared, and cannot share names.

    Well if you want one library to be able to use another you would need to make it require that library, essentially ordering the code so that the libraries can see the necessary components. In JASS you cannot reference a function that is declared below the function you are referencing it from.

    It basically refers to how many instances can be in-play at any given time. Multiple-unit-instance-able basically means that no matter how many units there are, there can be one instance of "something" for each unit.

    Any ideas on what? I still don't understand what you mean by "allows you to capture a unit and then you can bring another type of unit to the captured unit".
     
  16. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    when you use scopes and libraries, can the initializer be outside of the library (or scope) or can it only be used if it is inside?

    What character is used for multiplication? is it "*"?

    What is OOP?

    Why do some conditional statements say:
    Code (vJASS):
    if (b) then //actions


    Without anything to compare it with? Like:
    Code (vJASS):
    if b == true then //actions
     
    Last edited: Apr 23, 2010
  17. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
    Can you have a function return a value without using the return command inside the function like this:
    Code (vJASS):
    function Sum takes integer A, integer B returns C
        local integer C = A + B
    endfunction
    function CallSum takes nothing returns nothing
        local integer A = 3
        local integer B = 2
            call Sum(a, b)
            call BJDebugMsg (i2s(C))
    endfunction
    // would it still return 5 and display it? (I can’t test it because my laptop was taken away because of grades so)

    or do you have to put a type of value when specifying what it returns?

    what is the function used to get all units of a type? is it GetUnitsOfType('/*rawcode*/)?
     
  18. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,036
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Code (vJASS):
    function Sum takes integer A, integer B returns integer
        return A + B
    endfunction
     
    function CallSum takes nothing returns nothing
        call BJDebugMsg (I2S(Sum(3,2)))
    endfunction
     
    // or //
     
    function Sum takes integer A, integer B returns integer
        return A + B
    endfunction
     
    function CallSum takes nothing returns integer
        local integer C = Sum(3,2)
        call BJDebugMsg (I2S(C))
        return C
    endfunction
     
     


    Inside only. And it's best to use
    private function Init
    so that you can have another initializer in another scope/library with the same name.
    http://jass.sourceforge.net/doc/expressions.shtml

    Object-oriented Programming. (Wiki it). In Jass, those are structs.

    Do it like that. If (b) then is the same as if b == true then, and if not b then is the same as if b == false then.

    Keep it without the == false/== true imo, because it's easy to accidentally disclude the second = operator.
     
  19. kennyman94

    kennyman94

    Joined:
    Nov 22, 2009
    Messages:
    181
    Resources:
    0
    Resources:
    0
     
  20. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,036
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Integer:

    if a > b then


    Object:

    if IsUnitInGroup(unit,group) then