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] 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. 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
    strings in simple terms are words... when you use strings you enclose them in ""...

    Code (vJASS):

    local string A = "I am a string"
     
     
  2. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    What do mean? Like, is there a JASS example? I'm really sorry...
     
  3. 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
    strings are just words, like what you make the function DisplayText display... they can also be used to set the paths of certain objects like model paths

    Code (vJASS):

    local string Text = "Hello World"
    local string Path = "Units\\Blademaster.mdl" //Note: this is a hypothetical path to the blademaster model
    call BJDebugMsg(Text)
    //this will show a debug message saying Hello World
    call AddSpecialEffect(Path, 0.00, 0.00)
    //this will show a special effect using the model on the specified path
    //And oh, when you use paths, always use \\ rather than \
     
     
  4. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Now I get it, thanks so much! Uhm... I really hope you don't mind me asking but, I usually hear that Hashtables are accompanied by Strings, what are Hashtables and is it true?
     
  5. 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
    hashtables are like a variable array which store variable arrays... in simpler terms its like a cabinet which lets you store data in an organized way...

    and we usually use strings to organize the data inside a hashtable
    Code (vJASS):

    local hashtable Hash = InitHashtable()
    call SaveReal(Hash, GetHandleId(Miss_Foxy), StringHash("Age"), GetAge(Miss_Foxy))
    //Here we save your age into a cabinet named Hash, on a folder named Miss_Foxy, into a data sheet called Age
    //The function StringHash converts the string "Age" into an integer
    //Basically you could use any integer on that part, but we use a string to better organize things
    //and to make it self-explanatory

    //example of directly using an integer rather than a string:
    //the function above is easier to understand than this one below right?
    call SaveReal(Hash, GetHandleId(Miss_Foxy), 1, GetAge(Miss_Foxy))
     
     
  6. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Hmm... What else could I ask about that would help me in learning JASS...
    Haha, you're just like my other JASS Teacher, thank you so much!

    PS: By the way, what are Structs?
     
  7. 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
    structs are just another type of data storage... it saves data into variable arrays (but can also save data into non-arrays)...

    Code (vJASS):

    //This one
    globals
       unit array Hive
    endglobals

    //is the same as this

    struct
       unit Hive
    endstruct
    //this is just the basic idea
    //when you learn to use them, u'll realize how amazing they are
    //And structs are AWESOME, they make things a lot easier... ^_^
     
     
  8. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Full commented look into the background workings of structs

    Code (vJASS):

    //a struct that extends an array is code with the syntactic sugar of a struct
    //this means that no extra code is generated

    //structs normally generated create, destroy, and onDestroy
    struct Hello extends array
        //instantiation can be a tricky thing. When a struct is created, you have to ensure
        //that the instance returned is unique. Furthermore, when a struct is destroyed,
        //you need to reuse that struct's instance to save on memory

        //instanceCount is a counter that continues to increase as new instances are created
        private static integer instanceCount = 0 //how many Hello's that are created

        //recycleCount is a counter that continues to increase as structs are destroyed
        //this is to ensure that destroyed instances are used the next time the struct
        //is created
        private static integer recycleCount = 0 //how many Hello ids that were recycled

        //recycle is an array that stored the destroyed instances
        private static integer array recycle //an array storing recycled Hello's

        //this is the create method, a method that creates unique instances of the struct
        //thistype is a keyword that translates into the struct's name
        //in this case, thistype would be Hello
        //if the struct was named BooYa, thistype would be BooYa
        public static method create takes nothing returns thistype
            //this is a keyword that refers to the current instance
            //static methods are like regular functions, so they don't get a this, which is
            //why I was able to declare one
            //static methods are called via struct.method()
            local thistype this

            //first check for any destroyed structs
            if (recycleCount > 0) then //if there are Hello's waiting to be reused
                //decrease the counter so that you are on the right slot in the array
                set recycleCount = recycleCount - 1 //dec counter

                //set the current instance to the destroyed struct
                set this = recycle[recycleCount] //use it
            else
                //if there are no destroyed structs, make a new one by increasing
                //the instance counter
                set instanceCount = instanceCount + 1 //0 is null, so first inc by 1

                //set the current instance to the instance counter
                set this = instanceCount
            endif

            //perform creation code here :O

            //return the created struct
            return this
        endmethod

        //destroy is called when the struct is to be destroyed
        //this is not a static method
        //a non static method translates to this (using destroy as an example)
        //public static method destroy takes thistype this returns nothing
        //the instance of the struct is automatically passed in
        //they are called via structInstance.method()

        public method destroy takes nothing returns nothing
            //remember this is passed in, so it exists!
            //store this into the recycle variable
            //the first struct destroyed would be recycle[0] = this
            set recycle[recycleCount] = this
            //increase recycle counter
            set recycleCount = recycleCount + 1

            //if create was called, recycleCount would be decreased back down to 0
            //and recycle[0] would be used

            //put destruction code here
        endmethod
    endstruct
     


    Above allows this
    Code (vJASS):

    local Hello h = Hello.create()
    call h.destroy()
     


    There are also method operators, overloaded operators, fields, readonly fields, and static fields.

    On top of this, it would be good to learn how to do object creation using Lua. I have finally finished the scripts necessary for it and included a walk through guide ; ).

    Object Creation using this ensures your scripts don't collide with other scripts.

    http://www.hiveworkshop.com/forums/submissions-414/system-lua_jass_globals-185917/
     
  9. 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
    @Nestharus - what does these,overloaded operators, fields, readonly fields, do? never used them... ^_^

    btw, that system looks so cool...

    @Miss_Foxy - here are some tuts on vJASS if you want to learn more about structs
    vjass OOP
    Indexer

    its also a good idea to look up for Vexorian's vjass guide...
     
  10. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    overloaded: [], []=, ==, =, >, <, etc

    Some of the comparisons aren't enabled (I rarely use them, so don't know which work and which don't, but when vjass throws an error regarding them, it gives you a list of working ones).

    method operators are
    Code (vJASS):

    integer h
    public method operator hello takes nothing returns integer
        return h
    endmethod
    public method operator hello= takes integer i returns nothing
        set h = i
    endmethod
     


    They can also be static. They are treated like regular fields when used
    set s.hello = 5
    local integer i = s.hello

    fields are variables in structs >.>.

    readonly fields are variables with readonly...
    Code (vJASS):

    struct h extends array
        readonly integer i
    endstruct
     


    Then there are interfaces and function interfaces, although I don't suggest their use as they have quite a bit of overhead o-o.
     
  11. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Thanks guys. What is a readonly or static? I've never really heard of those...
     
  12. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Foxy,
    You really should read a JASS tutorial and JASS helper manual for vJASS terms.
     
  13. 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
    a static struct member/field is shared by all the struct instances unlike non-static ones which are unique per instance...

    in simpler terms:
    static struct members/fields = non-array variable
    non-static struct members/fields = array variables
     
  14. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Is there other forms of JASS other than JASS, cJASS, vJASS or JASS2?
     
  15. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
  16. 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
    Zinc
    short comparison of vjass and zinc

    Code (vJASS):

    //! zinc
    library ShorterCodesButHarderToRead
    {
         function LooksLikeC ()
         {
            BJDebugMsg("This is Zinc");
         }
    }
    //! endzinc

    library LongerCodesButEasierToRead
         

         function DoesNotLookLikeC takes nothing returns nothing
           call BJDebugMsg("This is vJASS")
         endfunction
     
    endlibrary
     
     
  17. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    So... It can be used in Warcraft III too? I wonder if there are others besides that one, I'm suddenly interested in the topic of Triggering and Programming Warcraft III stuff :O
     
  18. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Yeah, it can be used in Warcraft III as well, as long as you have Jass NewGen Pack. As far as other means of triggering in warcraft III, there is only WeWarlock (which is somewhat deprecated and not used by many). That is pretty much it though.
     
  19. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Hmm... How do you actually 'make' a programming language? What does a Warcraft III one actually compose of? I'm kind of curious, sorry...
     
  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
    warcraft's programming language is JASS... every other thing (GUI, vJASS, zinc, etc) are transformed to jass when a map compiles...

    on the first question, IDK...