• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

No BJ or BJ?

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
What's the difference between functions in jass that have a BJ or no BJ?
Example:
JASS:
call DialogAddButtonBJ( udg_StartDialog, "All Random" )
Create a dialog button using DialogAddButtonBJ.

JASS:
call DialogAddButton( udg_StartDialog, "All Random", 1 )
Creating without BJ.

What's the real difference (Other than without BJ taking another value.)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
The BJ function does this:

JASS:
function DialogAddButtonBJ takes dialog whichDialog, string buttonText returns button
    set bj_lastCreatedButton = DialogAddButton(whichDialog, buttonText,0)
    return bj_lastCreatedButton
endfunction

So basically it sets the variable "bj_lastCreatedButton" (which is a dialog button variable) to the native "DialogAddButton(...)".
(Natives are the functions that do not call any other functions, they access the raw code of warcraft directly).

However, this is a roundabout way, the same would be this:

JASS:
set variable = DialogAddButton(whichDialog, buttonText,0)

The BJ takes longer because it has to access a function that does the exact same thing as the BJ itself.
It's advised you never use BJ's, because sometimes they're plain useless, and at other times they're extremely bug and unwieldy (examples of both below).


JASS:
function AddHeroXPSwapped takes integer xpToAdd, unit whichHero, boolean showEyeCandy returns nothing
    call AddHeroXP(whichHero, xpToAdd, showEyeCandy)
endfunction

JASS:
native AddHeroXP takes unit whichHero, integer xpToAdd, boolean showEyeCandy returns nothing

This is useless because all it does is swap the order it takes the variables in.
I can't explain it any better, it's just... not logical. The BJ calls the native for no reason, so you should use the native (by the way: GUI uses the BJ).


JASS:
function CountUnitsInGroup takes group g returns integer
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupCountUnits = 0
    call ForGroup(g, function CountUnitsInGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_groupCountUnits
endfunction

A better idea would be to use a variable to count the units in a group.
This BJ is rather big (beware: there are far worse BJ's) and can easily be avoided.
 
BJs are slower. PERIOD

BJs are useless functions that use natives (function calls are expensive, so we just use natives instead of BJs)

That native should be about 2x faster than that BJ since all the BJ does is call it after doing a small modification.


Blizzard.j (A collection of 924 BJs) is just an API (Alternate programming interface)
It's useless because all it does is kill speed.
 
Status
Not open for further replies.
Top