1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. The member Kam is making HIVE coasters. Take a look. For every coaster you buy, Hive gets $1.
    Dismiss Notice
  3. Buy it, use it, break it, fix it, trash it, change it, mail - upgrade it. Join (Optionally) Paired Techtree Contest #11 - Techno Magic now!
    Dismiss Notice
  4. Dismiss Notice
  5. Hero Contest #8 is up and running! This time it's a joint contest between artists and coders. Go here for team matchmaking.
    Dismiss Notice
  6. The ninth Concept Art Contest has launched. Enter now!
    Dismiss Notice
  7. Our first StarCraft contest, The Galaxy Terraining Contest #1 - World Wonders has started. Enter to show off your Galaxy Editor skills and win a custom rank icon among other things.
    Dismiss Notice
  8. Ever wanted to get your sets ready for fast texturing while still having fun? Now it is possible with our newest Mini-Texturing Contest.
    The Skeleton Units need your dire help!
    Dismiss Notice

Jasshelper 2011-12-19

Discussion in 'Warcraft Editing Tools' started by cohadar, Dec 19, 2011.

  1. Nestharus

    Nestharus
    Joined:
    Jul 10, 2007
    Messages:
    6,105
    Ahem, in constant timer loop 32, the code in the module may be calling code in the struct, and that code in the struct may be calling the code back in the module.


    user timer code -> call destroy() (in struct)
    struct code call stop (in module)

    the destroyer has to be above the module so that the user's timer code can call it.
     
  2. Troll-Brain

    Troll-Brain
    Joined:
    Apr 27, 2008
    Messages:
    2,365
    Then it's the design of the code which is flawed, because how jass work.
     
  3. Nestharus

    Nestharus
    Joined:
    Jul 10, 2007
    Messages:
    6,105
    well, it relies on the inliner working properly ;\
     
  4. Tirlititi

    Tirlititi
    Joined:
    Jul 11, 2010
    Messages:
    396
    I have a suggestion about the hooks. I think they should be more flexible.

    There should be 2 more kinds of hooks, in my opinion :
    - One that only calls the function instead of doing all this TriggerEvaluate thing. We definitely should have the choice, even if this solution causes problems in several situations, it would be usefull for the simpliest hooks that only use native functions and don't run much code. You may also give the option to use a TriggerExecute in the same way.
    - One that totally replace the hooked function. Of course, the hook must not act inside the hooking function in that case. It would allow to call the function after the hooked one and get it's return value, for instance. It would also enable to make multiple calls (let's say if 2 objects are linked and that a function applying to one must apply to the other) or emulate the function with another.

    An example of what could be done with those :

    Code
    Code (vJASS):
    function CreateItemHook takes integer itemid, real x, real y returns item
        local item it = CreateItem(itemid, x, y)
        call SetItemInvulnerable(it, true)
        return it // I know it leaks but that's example.
    endfunction

    // call and replace are the hook options.
    // The 2 last words are the usual arguments.
    hook call replace CreateItem CreateItemHook

    ...

       local item it = CreateItem('I000', 0, 0)


    And the output would be something like :
    Code (vJASS):
    globals
    trigger array st___prototype2
    item f__result_item
    integer f__arg_integer1
    real f__arg_real1
    real f__arg_real2

    endglobals

    // In current jasshelper, those functions are always created even if the "execute" version is never used.
    // You may adapt the creation of them to the hook option ("call", "evaluate" or "execute").
    function sc___prototype2_execute takes integer i,integer a1,real a2,real a3 returns nothing
        set f__arg_integer1=a1
        set f__arg_real1=a2
        set f__arg_real2=a3

        call TriggerExecute(st___prototype2[i])
    endfunction
    function sc___prototype2_evaluate takes integer i,integer a1,real a2,real a3 returns item
        set f__arg_integer1=a1
        set f__arg_real1=a2
        set f__arg_real2=a3

        call TriggerEvaluate(st___prototype2[i])
     return f__result_item
    endfunction

    // Hook function moved to the header. In the worse case, it just pops an "undeclared function error".
    function CreateItemHook takes integer itemid,real x,real y returns item
        //hook: CreateItemHook call replace
        local item it= CreateItem(itemid, x, y) // CreateItem not hooked here.
        call SetItemInvulnerable(it, true)
        return it
    endfunction

    ...

        call CreateItemHook('I000', 0, 0)

    ...

    // jasshelper__initstructs functions ...
     


    And the same example with an "evaluate" option :
    Code (vJASS):
    function CreateItemHook takes integer itemid, real x, real y returns item
        local item it = CreateItem(itemid, x, y)
        call SetItemInvulnerable(it, true)
        return it
    endfunction

    // Same as "hook replace CreateItem CreateItemHook"
    hook evaluate replace CreateItem CreateItemHook

    ...

       local item it = CreateItem('I000', 0, 0)


    And the output would be something like :
    Code (vJASS):
    globals
    trigger array st___prototype2
    item f__result_item
    integer f__arg_integer1
    real f__arg_real1
    real f__arg_real2

    endglobals

    function sc___prototype2_execute takes integer i,integer a1,real a2,real a3 returns nothing
        set f__arg_integer1=a1
        set f__arg_real1=a2
        set f__arg_real2=a3

        call TriggerExecute(st___prototype2[i])
    endfunction
    function sc___prototype2_evaluate takes integer i,integer a1,real a2,real a3 returns item
        set f__arg_integer1=a1
        set f__arg_real1=a2
        set f__arg_real2=a3

        call TriggerEvaluate(st___prototype2[i])
     return f__result_item
    endfunction

    function h__CreateItem takes integer a0, real a1, real a2 returns item
        //hook: CreateItemHook
    return sc___prototype2_evaluate(1,a0,a1,a2) // As a side note : this doesn't leak anymore.
    endfunction

    ...

    // Function not moved to top.
    function CreateItemHook takes integer itemid,real x,real y returns item
        local item it= CreateItem(itemid, x, y) // CreateItem not hooked here.
        call SetItemInvulnerable(it, true)
        return it
    endfunction

    //processed hook: hook evaluate replace CreateItem CreateItemHook

    ...

        call h__CreateItem('I000', 0, 0)

    ...

    // jasshelper__initstructs functions called at map initialization :
    function sa___prototype2_CreateItemHook takes nothing returns boolean
     local integer itemid=f__arg_integer1
     local real x=f__arg_real1
     local real y=f__arg_real2

        local item it= CreateItem(itemid, x, y) // CreateItem not hooked here either.
        call SetItemInvulnerable(it, true)
        set f__result_item= it
        return true
    endfunction

    function jasshelper__initstructs1712796703 takes nothing returns nothing
        set st___prototype2[1]=CreateTrigger()
        call TriggerAddAction(st___prototype2[1],function sa___prototype2_CreateItemHook)
        call TriggerAddCondition(st___prototype2[1],Condition(function sa___prototype2_CreateItemHook))

    endfunction
     



    I hope it's clear and not too hard to make.

    Thanks and congrats to update this tool. That's really an usefull work :goblin_good_job:.
     
  5. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,115
    Do you mean the JASS text? That is a TESH thing, you can just click "Options" in your trigger editor to change it. (or whatever the button is) It should have some color scheme options iirc.

    @Tirlititi: I also hope that update occurs, hooking would be pretty powerful then--and a lot more useful.
     
  6. Adiktuz

    Adiktuz
    Joined:
    Oct 16, 2008
    Messages:
    9,699
    @PurgeandFire111 - yeah, found it... ^_^
     
  7. Magtheridon96

    Magtheridon96
    Joined:
    Dec 12, 2008
    Messages:
    6,029
    edit
    Nevermind >.>
     
    Last edited: Apr 11, 2012
  8. Tirlititi

    Tirlititi
    Joined:
    Jul 11, 2010
    Messages:
    396
    I don't get it and I don't think you got it neither. :ogre_icwydt:
     
  9. Adiktuz

    Adiktuz
    Joined:
    Oct 16, 2008
    Messages:
    9,699
    I have a question, what are hooks? XD
     
  10. mckill2009

    mckill2009
    Joined:
    Mar 10, 2009
    Messages:
    4,681
    Code (vJASS):

    function hookme takes string s returns nothing
       call BJDebugMsg(s)
       call BJDebugMsg("hookme")
    endfunction

    hook BJDebugMsg hookme
     
     
  11. Bribe

    Bribe

    Code Moderator

    Joined:
    Sep 26, 2009
    Messages:
    7,338
    That's an infinite loop.
     
  12. Magtheridon96

    Magtheridon96
    Joined:
    Dec 12, 2008
    Messages:
    6,029
    And that, my friends, is what happens when you read a post backwards and expect to get anything out of it. >.>
    (No, I'm not talking about you, I'm talking about myself.)
     
  13. cohadar

    cohadar
    Joined:
    Jun 16, 2007
    Messages:
    234
    Hooks are one of those arcane jasshelper features used by 0.0001% of mapmakers.
    They replace standard wc3 functions with your own wrapper function.
    In this they are similar to blizzard's BJ functions, but are worse because it is not obvious in other triggers code that something has changed.

    Imho when you need to replace a default wc3 function with your own you should do it manually.

    You can easily find all instances of a certain function by searching through your input .j script.
    It is located in:
    jassnewgenpack5d\logs\input_war3map.j - my jasshelper mod
    jassnewgenpack5d\logs\inputwar3map.j - original jasshelper
     
  14. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,115
    It isn't for personal mapping so much as it is for systems. Hooking is rarely used because it is slow and very limited--we tend to avoid it even if it is a viable option either because: (A) it is slow or (B) we can't do what we actually want to 100%.

    There are certain systems such as IDDS (just giving an example) which could benefit off this, as it makes the implementation/use much easier; especially if you already have code in your map.

    At the moment hooks are weak and don't have many uses, but with a hook rewrite option people may be a bit more creative with their systems. For example, one could hook-rewrite certain registered player events and make them so they apply only for players actively playing to reduce handle count. Of course, that sort of thing isn't necessary, but it can give people more creativity in system design and will make implementation of certain systems far easier. (especially for GUI users)
     
  15. Adiktuz

    Adiktuz
    Joined:
    Oct 16, 2008
    Messages:
    9,699
    I've read the new manual and well, I just want to ask what is the limit for the sized arrays and the struct instance with more space... XD
     
  16. jim7777

    jim7777
    Joined:
    May 27, 2009
    Messages:
    481
    arrays have infinite value..

    but it should be <= 8192.. and that should be the recommended value..

    (dunno why blizzard made it infinite)

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

    hmm.. will there be any update like optimizing some sort of BJ funcs?? like converting them to its native equivalent.. lol (even though optimizer does this.. most of the time..)
     
  17. Adiktuz

    Adiktuz
    Joined:
    Oct 16, 2008
    Messages:
    9,699
    Uhm, I was asking because the documentation says that you can bypass the 8191 limit by using SIZED ARRAYS...

    I believe this wasn't present on the original manual of JH and was just added recently...
     
  18. Bribe

    Bribe

    Code Moderator

    Joined:
    Sep 26, 2009
    Messages:
    7,338
    No, that's been there forever. Sized arrays compile into large if/else blocks. With hashtables introduced several years after vJass introduced sized arrays, the vJass approach is more or less deprecated.
     
  19. Adiktuz

    Adiktuz
    Joined:
    Oct 16, 2008
    Messages:
    9,699
    Ah... Okay... thanks for clearing it up... XD
     
  20. PurplePoot

    PurplePoot
    Joined:
    Dec 14, 2005
    Messages:
    11,151
    I know I'm rather late to the party, but should this really be called JassHelper seeing as it's unofficial and done by someone with a very different view on what vJASS should be than Vexorian had?