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 haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  4. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  5. 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] BJ Functions

Discussion in 'Triggers & Scripts' started by Hashjie, May 28, 2009.

  1. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    hey all, I heard that it's better to avoid BJ functions in your map...

    So can anybody give me a list of BJ functions that you can better avoid in your map by replacing it with original functions?

    example:

    DestroySpecialEffectBJ -> DestroySpecialEffect

    I need this because I am going to change every single BJ function in my GUI into normal functions and I need to know which ones I can change :)
     
  2. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    About any function in blizzard.j should be avoided and replaced by functions from common.j...
     
  3. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    ok thanks, thats the only thing I needed to know... Now I can change every BJ function... (Thought maybe there are some BJ functions that doesn't have their native functions)

    may I ask why they have to be changed b.t.w.?
     
  4. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,875
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    They have a "BJ" in their name... how hard to find.

    You can check what a function does and see if it is worth it too, seeing as there are some BJs that will look exactly like your code without them.
     
  5. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    I know that they are not hard to find, but I am changing every action that I have in my trigger editor (in GUI) to change into a function without the BJ added. That's taking me a lot of time and I wanted to be sure to change it correctly...
     
  6. Darkyvm

    Darkyvm

    Joined:
    May 16, 2007
    Messages:
    202
    Resources:
    1
    Spells:
    1
    Resources:
    1
    You should be careful with that, there are BJ functions that you can inline (turn into a native function, basically what you're doing) just by removing the BJ, but there are others like PolarProjectionBJ that are different and just removing the BJ won't work, for example:

    A function that can be inlined simply by removing BJ:

    Code (vJASS):
    function StopMusicBJ takes boolean fadeOut returns nothing
        call StopMusic(fadeOut)
    endfunction
    //this BJ function simply calls a native with the same name
    //removing the BJ is enough to inline it


    A function that can't be inlined simply removing the BJ, you have to do more to properly inline it:

    Code (vJASS):
    function PolarProjectionBJ takes location source, real dist, real angle returns location
        local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
        local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
        return Location(x, y)
    endfunction
    //removing the BJ won't work here
    //since the function PolarProjection doesn't exist
    //to inline this you'll have to write the function's code
    //in your trigger, while paying attention to remove
    //any unecessary part (the return location, for example)


    Hope this helped you.
     
  7. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,234
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    If you have jass newgen pack (JNGP) there is a "function list" button. I'd recommend looking there. Generally BJ functions should be avoided, but sometimes they are quite helpful.
     
  8. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    but why? why should they be avoided??

    EDIT: I'm NOT creating a script in jass.... I'm changing the trigger editor to my needs by removing all BJ functions in GUI.... This is what I mean:

    http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=79059

    so I want to know why we should avoid BJ functions, because almost every single action in GUI is a BJ function...
    Look in that tutorial if you want to know what I mean...

    EDIT:
    I am not trying to inline... I just want to know what the BJ function means... Does it mean that it slows down something? Does it mean that it leaks?? I have no idea... Please inform me....

    EDIT:
    (ow sry I didn't read correctly.... so what would you suggest me to do? which BJ functions should I remove and which one should I not? How can I see that the function exists?)
     
    Last edited: May 29, 2009
  9. SerraAvenger

    SerraAvenger

    Joined:
    Apr 16, 2007
    Messages:
    149
    Resources:
    4
    Maps:
    4
    Resources:
    4
    Every time you call a function in JASS, it needs some processing time.
    Since most BJs are proxies (just calling another function with almost the same arguments), you get 2 function calls where you'ld just need one (the native call + the bj that is calling the native).
    Those BJ's that aren't proxies are often quite useful.
     
  10. Darkyvm

    Darkyvm

    Joined:
    May 16, 2007
    Messages:
    202
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Why should we avoid BJs? Well, think for a moment.
    What would be faster:

    Ask someone to get an apple for you.

    Ask someone to ask someone to get an apple for you.

    BJ functions are basically this, you are calling a function that simply calls another function, wouldn't it be faster to just call the function itself instead of calling the BJ?

    Why all GUI functions are BJs? Hell if I know, Blizzard does some crazy things with JASS.

    But as SerraAvenger said, there are a few BJs that could be useful, for example, TriggerRegisterAnyUnitEventBJ is a BJ, but since it does a lot more than just calling TriggerRegisterAnyUnitEvent, it can be useful (and in some cases, faster), than inlining the function.

    JassCraft (http://www.wc3c.net/showthread.php?t=80051) is a great program for this, it has a function list and allows you to see the code of each function (except for natives, but you shouldn't worry about that).
     
  11. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    ok thanks a lot for explaining I fully understand now +rep to you....

    and does this mean that whenever a BJ function has a native function that it can be replaced??
     
  12. SerraAvenger

    SerraAvenger

    Joined:
    Apr 16, 2007
    Messages:
    149
    Resources:
    4
    Maps:
    4
    Resources:
    4
    if and only if it does nothing but calling that native, yes.
     
  13. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,234
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    I've found certain excuses. Using GetDyingDestructable() simply returns GetTriggerWidget(), however replacing the fore with the latter can and will cause problems.

    Here is a simple trigger in a map of mine:

    Code (vJASS):



    function Trig_Regrow_Trees_Actions takes nothing returns nothing
        call TriggerSleepAction(1)
        call SetDestructableAnimation(GetDyingDestructable(),"Birth")//GetDyingDestructable cannot be simplified to it's native...why?
        call SetDestructableAnimationSpeed(GetDyingDestructable(),3)
        call TriggerSleepAction(19.6)
        call SetDestructableAnimation(GetDyingDestructable(),"stand")
        call SetDestructableAnimationSpeed(GetDyingDestructable(),1)
        call DestructableRestoreLife(GetDyingDestructable(),GetDestructableMaxLife(bj_lastCreatedDestructable),false)
    endfunction

    function InitTrig_regrowTrees takes nothing returns nothing
        set gg_trg_regrowTrees = CreateTrigger()
        call TriggerRegisterDestDeathInRegionEvent(gg_trg_regrowTrees,bj_mapInitialPlayableArea)
        call TriggerAddAction(gg_trg_regrowTrees,function Trig_Regrow_Trees_Actions)
    endfunction

     
     
  14. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,875
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    You will actually just end up with the same code. Some people do this just to get rid of the evil red color. :p
     
  15. Mechanical Man

    Mechanical Man

    Joined:
    Jan 18, 2005
    Messages:
    5,383
    Resources:
    39
    Models:
    30
    Icons:
    3
    Packs:
    1
    Maps:
    4
    Tutorials:
    1
    Resources:
    39
    But that calling the other function really consumes so much time?
     
  16. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,875
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Not at all, it hardly takes any time. But it happens hundreds of thousands times, which over time does consume time (now isn't this a silly-paradox looking sentence?).
     
  17. Hashjie

    Hashjie

    Joined:
    Apr 20, 2009
    Messages:
    1,515
    Resources:
    0
    Resources:
    0
    yes it is and that sentence is exactly the reason why I want it out of my GUI triggers...
     
  18. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    The typical TriggerRegisterEvent only happens once per game (exceptions are very rare), and thus being a BJ doesn't really matter. Other BJ functions worth using would be BJDebugMsg, which too is an additional call, but nobody cares about that because it's used for debugging...

    Also, getting rid of BJ functions in GUI triggers is, to say the least, pretty stupid. Just write directly in jass or stick to gui, because BJ's aren't the only reason why GUI leads to inefficient triggers.
     
  19. Dreadnought[dA]

    Dreadnought[dA]

    Joined:
    Feb 23, 2007
    Messages:
    810
    Resources:
    0
    Resources:
    0
    Some BJ's are not bad. They sometimes do a math function for you like Modulo (although it doesn't have BJ in its name).
     
  20. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    If you know your integers are positive, Modulo could (and should) be avoided too.