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. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    They not only need the special RtC launcher, but they need all dlls used by the map.

    This is the reason why nobody uses RtC =P. How many players do you think would play an RtC map? Very few if any.
     
  2. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Hmm... Is there another program then, which allows majority of the players to play on maps using other languages?
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    There is not.
     
  4. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Okay then:)
    Would you give me a basic question to test my current knowledge of JASS, I'd love to see how far I've come.
     
  5. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    1. What are two methods for achieving recursive event data when creating custom events?

    2. How are structs instantiated? Please create an array struct with a create and destroy method.

    3. What is a dequeue? Create a single instance. Create a multiple instance dequeue.

    4. What is a stack? Show two types of stacks.

    5. What is a queue?

    6. With a dequeue, show another method of recycling instantiated instances.

    7. What is faster? Looping through an array or looping through a linked list?

    8. How would you desync a game with GetLocalPlayer?

    9. What is the proper method for enumerating over all units on the map? Please write out the code.

    10. Should initialization for a script be done in a module onInit method, a struct onInit method, a library initializer, or a scope initializer?

    11. What precisely is the difference between a boolexpr and a filterfunc?

    12. Why is it bad practice to use TriggerRemoveCondition?

    13. How are triggers run in events? Show the entire model.

    14. What is faster on an event: an action or a condition? Why?

    15. What is faster: TriggerExecute or TriggerEvaluate? Why?

    16. Why do people avoid ExecuteFunc?

    17. How would you retrieve the name of a method and then display its entire name including proper scoping.

    18. How would you check to see if a method exists in a module that's implemented into a struct?

    19. How would you only put a global into a map if another global was true?

    20. How do you chain boolexprs together?

    21. What is the order of operations in boolean expressions.

    22. How many seconds can decay run for before it fires off the decay event.

    23. Why does undefend fire one to two times in unit indexing?

    24. How would you retrieve the gold cost of an item?

    25. What's faster, SetUnitPosition or SetUnitX + SetUnitY and why?

    26. What is an indexed array?

    If you can answer all of those, you are well on your way to becoming a pro : P.
     
  6. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Are they in the order of ascending difficulty?
     
  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
    wow, those questions are pretty hard for a "basic" jass question... ^_^

    anyway, good luck!
     
  8. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    Nestharus,
    You should post the answers later,i'm curious about half of the questions D:
     
  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
    me too...
     
  10. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Well, you guys could do a little research so that you can better learn this stuff. I know some of the answers are in my old vjass guide on TH, like the order of operations in boolean expressions. Other answers can be found in common.j.

    If you look at Event scripts as well as the TriggerRegister stuff, you can figure out how events run in JASS as well as the answers on conditions and actions.

    If you read up on ExecuteFunc, especially concerning benchmarks, you'll learn why it is typically avoided.

    If you look at SC2, you'll learn why strings are slow in wc3 ; P.

    Etc etc

    Yes, I know all the answers, but it's best to learn them on your own and discuss your findings so that they stick with you and so that you fully understand them ; D.
     
  11. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Maybe some practical questions too, like those that require making functions.
     
  12. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    1. What are two methods for achieving recursive event data when creating custom events?

    When events are run, data is normally associated with that event.
    GetTriggerUnit

    GetAttacker

    GetTriggerPlayer


    When creating custom events, it is easy enough to do this
    Code (vJASS):

    globals
        private trigger myEvent = CreateTrigger()
        private integer data = 0
    endglobals

    function OnMyEvent takes boolexpr c returns nothing
        call TriggerAddCondition(myEvent, c)
    endfunction
    function FireMyEvent takes integer d returns nothing
        set data = d
        call TriggerEvaluate(myEvent)
    endfunction
    function GetEventData takes nothing returns nothing
        return data
    endfunction
     


    But this can result in a problem.
    Code (vJASS):

    function Test takes nothing returns boolean
        local integer d = GetEventData() //d is now 1
        if (d == 1) then
            call FireMyEvent(2) //set d to 2
        endif
        if (d != GetEventData()) then
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "RECURSION ERROR!")
        endif
        return false //to prevent trigger actions from being run for no reason
    endfunction
    function Init takes nothing returns nothing
        call OnMyEvent(Condition(function test))
        call FireMyEvent(1) //data is now 1
    endfunction
     


    In events, event data should always be the same data as it was when the event first fired. In the above scenario, the data was first 1 but then becomes corrupted at 2. While this doesn't seem to be an issue, it can be a serious issue.

    Code (vJASS):

    //this will fire second
    function Test2 takes nothing returns boolean
        //remember that the event data become corrupt on the first fire?
        local integer d = GetEventData() //2 on first and second fires
        return false
    endfunction

    //this will fire first
    function Test takes nothing returns boolean
        local integer d = GetEventData() //d is now 1
        if (d == 1) then
            call FireMyEvent(2) //set d to 2
        endif
        if (d != GetEventData()) then
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "RECURSION ERROR!")
        endif
        return false //to prevent trigger actions from being run for no reason
    endfunction
    function Init takes nothing returns nothing
        call OnMyEvent(Condition(function Test))
        call OnMyEvent(Condition(function Test2))
        call FireMyEvent(1) //data is now 1
    endfunction
     


    And thus the major recursion error.

    Fire (1)
    ----run test1 (1->2)
    --------Fire (2)
    ------------run test1 (2)
    ------------run test2 (2)
    ----run test2 (2)

    There are two methods for solving this recursion error. The first poor way is to create an array type stack.

    Code (vJASS):

    globals
        private trigger myEvent = CreateTrigger()
        private integer stack = 0
        private integer array data
    endglobals

    function OnMyEvent takes boolexpr c returns nothing
        call TriggerAddCondition(myEvent, c)
    endfunction
    function FireMyEvent takes integer d returns nothing
        set stack = stack + 1 //increase the stack, thus making a new spot for event data
        set data[stack] = d //event the new spot to our current data
        call TriggerEvaluate(myEvent) //fire
        set stack = stack - 1 //revert to previous data
    endfunction
    function GetEventData takes nothing returns nothing
        return data[stack]
    endfunction
     


    If I were to fire the second example, it would run in this order-
    Test1- data 1
    Test1- data 2
    Test2- data 2
    Test2- data 1

    For a clearer understanding-
    Fire (1)
    ----run test1 (1)
    --------Fire (2)
    ------------run test1 (2)
    ------------run test2 (2)
    ----run test2 (1)

    As can be seen, the data is maintained ; D.

    The other and better way is by using locals to store the data to save on an array and a global declaration.

    Code (vJASS):

    globals
        private trigger myEvent = CreateTrigger()
        private integer data = 0
    endglobals

    function OnMyEvent takes boolexpr c returns nothing
        call TriggerAddCondition(myEvent, c)
    endfunction
    function FireMyEvent takes integer d returns nothing
        local integer prev = data //store the previous data in a local
        set data = d
        call TriggerEvaluate(myEvent)
        set data = prev //set the data back to the previous value
    endfunction
    function GetEventData takes nothing returns nothing
        return data
    endfunction
     


    This essentially does the same thing as the stack method but faster. Array reads are also quite a bit slower than var reads, so it's a better design.

    I'll answer this tomorrow
    ->2. How are structs instantiated? Please create an array struct with a create and destroy method.

    I'd prefer someone else to answer it on this thread by tomorrow. Please answer if you learned the answer to this within the last day. The answer and fully commented code can be found on this thread *hint hint*


    Interesting new Question
    What do you suppose this does?
    //! i local id = getvarobject("nfr2", "units", "UNITS_UNIT_EVENT")


    Inside of script that uses
    Somewhere
    //! import "luajass.FILE_NAME.j"


    The imported file before that function was run (doesn't exist)
    --------------------------------------------------
    After function was run for ABILITIES_UNIT_INDEXER
    Code (vJASS):

    globals//globals
    constant integer ABILITIES_UNIT_INDEXER='A!!!'
    endglobals//endglobals
     


    After function was run for UNITS_UNIT_EVENT
    Code (vJASS):

    globals//globals
    constant integer ABILITIES_UNIT_INDEXER='A!!!'
    constant integer UNITS_UNIT_EVENT='n!!!'
    endglobals//endglobals
     

    --------------------------------------------------

    In a function in map script
    set u = CreateUnit(Player(14), UNITS_UNIT_EVENT, WorldBounds.maxX, WorldBounds.maxY, 0)


    OM code (generates objects)
    Code (vJASS):

       //! i createobject("nfr2", id)
        //! i makechange(current, "unam", "Unit Event")
        //! i makechange(current, "unsf", "(Unit Event)")
        //! i makechange(current, "uico", "")
        //! i makechange(current, "uine", "0")
        //! i makechange(current, "udro", "-")
        //! i makechange(current, "usnd", "")
        //! i makechange(current, "ushb", "")
        //! i makechange(current, "umdl", "")
        //! i makechange(current, "uubs", "")
        //! i makechange(current, "ides", "")
        //! i makechange(current, "utip", "")
        //! i makechange(current, "usca", ".01")
        //! i makechange(current, "ussc", ".01")

        //! i local j = ((jass.globals.create(jassread())):read("ABILITIES_UNIT_INDEXER")).value:sub(2,5)
        //! i makechange(current, "uabi", "Aloc," .. j)
        //! i makechange(current, "ubdg", "0")
     



    Grimoire Samples omtest.lua file (in case you don't know om tool)
    Code (Text):

    setobjecttype("units") -- units, items, doodads, destructables, abilities, buffs, upgrades
    mergefile("input.w3u", import) -- merge, replace, import

    setobjecttype("doodads")
    mergefile("input.w3d", replace)

    setobjecttype("abilities")
    mergefile("input.w3a", merge)
    mergefile("more.w3a", merge)

    if objectexists("AHbz") then
      modifyobject("AHbz")
      if (currentobject() == "AHbz") then
        logf(currentobjecttype(), currentobject()) -- write debug information to log
        makechange(current, "Tip", 3, "Lame Level 3 Tooltip")
        makechange(current, "Cool", 2, 99.5)
        makechange(current, "achd", 1)
        makechange(current, "alev", 4)
      end
    end

    if objectexists("S000") then
      createobject("S000", "Sxyz") -- new id will be Sxyz
      if (currentobject() == "Sxyz") then
        logf(currentobjecttype(), currentobject()) -- write debug information to log
        makechange(current, "Hotkey", "Q")
        makechange(current, "Name", "My Chaos")
        makechange(current, "EditorSuffix", "(Peasant)")
        makechange(current, "CheckDep", 0)
        makechange(current, "Cha1", 1, "hpea")
      end
    end

    if objectexists("AHbz") then
      createobject("AHbz", generateid("AHbz")) -- new id will be generated as substitute for the passed AHbz id
      if (currentobject() ~= "") then -- "" would indicate that we do not have a current object
        logf(currentobjecttype(), currentobject()) -- write debug information to log
        makechange(current, "Levels", 10)
        makechange(current, "Tip", 6, "Blizzard Level 6")
        makechange(current, "ResearchTip", "Learn Blixxard")
        makechange(current, "Tip", 5, "fuckfuckfuckfuckfuck")
        resetchange(current, "Tip", 5) -- due to bad language
      end
      createobject("AHbz", generateid("AHbz"))
      if (currentobject() ~= "") then
        logf(currentobjecttype(), currentobject()) -- write debug information to log
        makechange(current, "Name", "LOL")
        resetobject(current)
      end
    end

    setobjecttype("doodads")
    createobject("ZOss", generateid("ZOss"))
    createobject("ZOss", generateid("ZOss"))
    createdid = currentobject()

    -- we set this again because the modded, unmodded and custom groups refer to the state of the last time we called setobjecttype
    setobjecttype("doodads")
    makechange(custom, "dmis", 0.55) -- min scale for all custom doodads
    makechange(original, "dmas", 300) -- max scale for all original doodads
    makechange(unmodded, "dmis", 0.99) -- min scale for all unmodded original doodads
    resetchange(modded, "dmas") -- max scale for all modded original doodads
    modifyobject(createdid)
    resetobject(current) -- resetobject also works with custom, original, unmodded, modded groups
     

    And this is the resource-
    http://www.hiveworkshop.com/forums/submissions-414/snippet-lua_get_var_object-185944/

    This is pretty much most of what you need to know concerning lua ;P.
     
  13. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    Thank you so much Nes!
    I'll try figuring them out first though, before reading the answers.
    Also, I hope this isn't too much but, would you give me a simple question about JASS (Just one) just so that I can test out what I've learnt in terms of placing words in JASS?
     
  14. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    ->Also, I hope this isn't too much but, would you give me a simple question about JASS (Just one) just so that I can test out what I've learnt in terms of placing words in JASS?

    Try the exercises in chapter 7 functions
    http://www.hiveworkshop.com/forums/1805960-post153.html

    edit
    New lua Convention up >: D

    Code (vJASS):

    //! externalblock extension=lua FileExporter $FILENAME$
        //! runtextmacro LUA_FILE_HEADER()
        //! i installscript([[function Hello() print("hi") end]], "1.0", "MyScript")
        //! i usescript("MyScript")
        //! i installjass([[
            //! i struct Tester extends array
                //! i private static method onInit takes nothing returns nothing
                    //! i call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "hello world")
                //! i endmethod
            //! i endstruct
        //! i ]], "1.0", "MyScript")
    //! endexternalblock
     


    http://www.hiveworkshop.com/forums/submissions-414/snippet-lua_file_header-186775/


    Since I'm like the only lua coder in entire community across wc3c, th, and thw, I GET TO DECIDE CONVENTION, FUAHAHAHAA >: D

    I will change convention daily cuz I rock so much! >: O

    I have released 140 hidden scripts on to the net for installing lua scripts. It is your mission to collect them all >: O.
     
  15. Miss_Foxy

    Miss_Foxy

    Joined:
    Oct 15, 2008
    Messages:
    2,821
    Resources:
    0
    Resources:
    0
    That's great to hear:)
    I'll try answering them, do keep the questions flowing!

    About the first question, how did you get the answer?
     
    Last edited: Jan 14, 2011