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.

[vJASS] If I want to use and learned vJass. Can I find basic tutorials?

Discussion in 'Triggers & Scripts' started by ALTELMA, May 10, 2012.

  1. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    I wonder about this

    Code (vJASS):

    Initailizer xxx
     


    Code (vJASS):

    constant
     


    tell me more, Plz!!
     
  2. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    This isn't really a tutorial, but vJass comes with a language reference which allows you to look up the exact function of all the various keywords and such.
     
  3. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
  4. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    for the
    initializer
    . You probably know that when the map is saved a .j file is created.

    At the end of the file is this:
    Code (vJASS):

    //***************************************************************************
    //*
    //*  Main Initialization
    //*
    //***************************************************************************

    //===========================================================================
    function main takes nothing returns nothing
        call SetCameraBounds(- 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), - 3328.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 3072.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 3328.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), - 3584.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
        call SetDayNightModels("Environment\\DNC\\DNCAshenvale\\DNCAshenvaleTerrain\\DNCAshenvaleTerrain.mdl", "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleUnit\\DNCAshenvaleUnit.mdl")
        call NewSoundEnvironment("Default")
        call SetAmbientDaySound("AshenvaleDay")
        call SetAmbientNightSound("AshenvaleNight")
        call SetMapMusic("Music", true, 0)
        call CreateCameras()
        call CreateAllUnits()
        call InitBlizzard()

        @call ExecuteFunc("jasshelper__init366")@

        call InitGlobals()
        call InitTrig_Initialization() // INLINED!!
        call ConditionalTriggerExecute(gg_trg_Initialization) // INLINED!!

    endfunction

    //***************************************************************************
    //*
    //*  Map Configuration
    //*
    //***************************************************************************

    function config takes nothing returns nothing
        call SetMapName("TRIGSTR_001")
        call SetMapDescription("TRIGSTR_003")
        call SetPlayers(2)
        call SetTeams(2)
        call SetGamePlacement(MAP_PLACEMENT_USE_MAP_SETTINGS)

        call DefineStartLocation(0, 0.0, 0.0)
        call DefineStartLocation(1, - 1024.0, - 384.0)

        // Player setup
        call InitCustomPlayerSlots()
        call SetPlayerSlotAvailable(Player(0), MAP_CONTROL_USER)
        call SetPlayerSlotAvailable(Player(1), MAP_CONTROL_COMPUTER)
        call InitGenericPlayerSlots()
    endfunction




    //All initializer functions called in proper order:

    function jasshelper__init366 takes nothing returns nothing


    call ExecuteFunc("scopeName___xxx")
    //------------------------------------

    endfunction

    Those 2 functions run before the map start (not sure though during loading or at initialization)

    As for
    constant
    , this keyword is not vJASS; it already exists before the making of vJASS.

    This will prevent the variables that use it from changing their values later in any part of the map script. But there are certain types of variables that can't use constant.
     
  5. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    False, however i think wc3mapoptimizer inline all constants, so something like that would be totally broken, each use of MY_GROUP would be replaced by CreateGroup(), and then a new group would be created :

    constant group MY_GROUP = CreateGroup()

    Constant handles are not that useful though, even if it's clearly a lack of wc3mapoptimizer to handle constant handles correctly. (but maybe it doesn't have this behavior anymore with the latest version, never tried)
     
  6. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    I remember that I got an error when making a constant hashtable.
     
  7. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    hashtable and group are default as constants, so no need to call them as such, since
    the only way for them to work is by declaring InitHashtable() and CreateGroup(), and
    you can never change it...
     
  8. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    I wonder if you ever tried google or look at the tuts section... anyway, mckill already posted the link for the language manual and Moyack's tutorial... You might wanna check the struct tutorial by Nes or the vJASS OOP tutorial...
     
  9. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Ok I'll try it.thank all guys.
     
  10. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Should not be possible in the first place because CreateGroup is no constant function. Then again, I have never quite understood the marking of constant functions in jass. Independently from that, a pile of functions do not work in the globals block.

    You can change the variable to null or another object of the kind.
     
  11. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    null variables are empty, therefore doesnt work...
     
  12. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Null variables are not unset, so you can at least read this null value or use it as a special parameter case in your own functions. My point was though that you can reset the variables and therefore such object vars are not constant by default. You are not even asked to give them an initial value.
     
  13. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    @Waterknight : Ok, i forgot about this constant function stuff.

    But yeah i also don't get the usefulness of constant native functions in jass.
    It would make sense if every constant functions could work with a constant variable, but i hardly see how for example
    constant native GetTriggeringTrigger    takes nothing returns trigger
    could work with a constant trigger variable.
    I mean, it seems that the way of which function are constant or not is "random".
    Well, all responses event functions seem constant (Get...), but i don't get why for example the math api functions are not constant.
    Same for
    constant native GetHeroLevel        takes unit whichHero returns integer

    Why it's constant and not
    native          GetHeroXP           takes unit whichHero returns integer
    , again just as an example.

    Talking about custom (not native) function, if it's defined in blizzard.j it could be used inside a constant variable which is inside the map script (in theory, never tried).

    Then the behavior of wc3mapoptimizer is not a real problem (if it acts like i say in the current version), since all create functions are not constant.
    It would still inline constant handles which use a constant function such as Player(), but at least it doesn't break the code (or make leaks).

    EDIT : Hmm, it will break a constant real variable which use GetHeroLevel, and probably with some other functions (i have not scrolled the whole common.j).
    Meh,
    GetHeroLevel
    would always return 1 or 0, dependly if it's an hero or not, because afair even preplaced units are leveled up during the map init.
    But still, a such constant would be still useful to know if an unit is an hero or not.
    Oh, wait ... you can't create an unit inside a constant variable definition :p
     
  14. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    @Troll-Brain: I said constant vars should not accept non-constant functions as values. Apparently, they do. At least optimizer could have a hint from that what to inline, or just leave all functions because printing in Order("abc") is likewise crap when it's not evaluated.
     
  15. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Hmm why he said that then :

    I'm 100 % sure InitHashtable works inside a not constant global variable definition, so well the script will "compile", but a constant variable "doesn't work" if it's used with a not constant function ?
    Is it a lack of script validity checking from japi ? (i mean the map will start or not ? , in other words the script will be considered as valid or not by the jass vm ?)
    Wc3 is crashing on map loading ?
    Or is he wrong ?
     
  16. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Yes, it seems I am mistaken.

    But I remember that I got error on saving telling me that this variable type can't be constant but I can't remember what. Sorry, for misleading, I will try to remember correctly.
     
  17. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Err I ask something. Why I can't compare between Global and Local Variable.It's error and display message "Don't Allow toCompare it"

    Code (vJASS):

    if(udg_Kill[tmpInt] == 3)then
        // Do stuff
    endif
     


    It can't uses this?
     
  18. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    make sure tmpInt is of type integer and that you actually created it on the same function where you are using it...
     
  19. ALTELMA

    ALTELMA

    Joined:
    Jan 4, 2009
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Code (vJASS):

    function Trig_Check_Integer_Actions takes nothing returns nothing
        local integer Int_Kill
       
        if(udg_ScoreKills[Int_Kill] == 3)then
            set udg_ScoreKills[Int_Kill] = udg_ScoreKills[Int_Kill] + 1
        endif
    endfunction

    //===========================================================================
    function InitTrig_Check_Integer takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerChatEvent( t, Player(0), "", false )
        call TriggerAddAction( t, function Trig_Check_Integer_Actions )
        set t = null
    endfunction
     


    error msg : Comparing two variables of defferent primatives types

    I'll try on other map it allow me, but My Map don't allow...
     
  20. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    try setting an initial value for Int_Kill