[Request] Removing BJs tutorial

jig7c

Stop reading me...-statement
Reaction score
123
Hello readers,

I need a tutorial, if possible, on removing BJs from jass scripts... from what i understand, BJs are slow, they suck, etc...
 

Executor

I see you
Reaction score
57
There are 3 types of BJs used (or not used) in JASS. (BJ = BlizzardJass).

First type

Well, many "BJ"s are simply wrappers for natives, for example:

JASS:
function AddItemToStockBJ takes integer itemId, unit whichUnit, integer currentStock, integer stockMax returns nothing
    call AddItemToStock(whichUnit, itemId, currentStock, stockMax)
endfunction

native AddItemToStock takes unit whichUnit, integer itemId, integer currentStock, integer stockMax returns nothing

function AttachSoundToUnitBJ takes sound soundHandle, unit whichUnit returns nothing
    call AttachSoundToUnit(soundHandle, whichUnit)
endfunction

native AttachSoundToUnit takes sound soundHandle, unit whichUnit returns nothing


These can be easily replaced by using the natives.

Second type

Another type of "BJ"s are BJs with GUI callback values:

JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction


You should not use them, cause they only set bj_lastCreatedUnit to the last unit created, but you don't need this in JASS as you can easily set the var yourself:

JASS:
local unit u = CreateUnit(...)


Third type

But, there are also useful BJs, which can be used:

JASS:
function BlightGoldMineForPlayerBJ takes unit goldMine, player whichPlayer returns unit
    local real    mineX
    local real    mineY
    local integer mineGold
    local unit    newMine

    // Make sure we're replacing a Gold Mine and not some other type of unit.
    if GetUnitTypeId(goldMine) != 'ngol' then
        return null
    endif

    // Save the Gold Mine's properties and remove it.
    set mineX    = GetUnitX(goldMine)
    set mineY    = GetUnitY(goldMine)
    set mineGold = GetResourceAmount(goldMine)
    call RemoveUnit(goldMine)

    // Create a Haunted Gold Mine to replace the Gold Mine.
    set newMine = CreateBlightedGoldmine(whichPlayer, mineX, mineY, bj_UNIT_FACING)
    call SetResourceAmount(newMine, mineGold)
    return newMine
endfunction

function RAbsBJ takes real a returns real
    if (a >= 0) then
        return a
    else
        return -a
    endif
endfunction


All in all:
- Replace the first type of BJs with the matching natives
- Never use the second type, as you can use the return value directly
- You may use the third type
 

jig7c

Stop reading me...-statement
Reaction score
123
looking good...
now the question is how do i know which ones to use and which ones not to use..

this trigger has few BJs, which im sure can be removed, but i dont' know how to go about doing it...
JASS:
private function team1win takes nothing returns nothing
    call CustomVictoryBJ ( GetEnumPlayer(), true, true )
endfunction

private function team2lose takes nothing returns nothing
    local string s = "The Palace is Destroyed!!"
    call CustomDefeatBJ( GetEnumPlayer(), s)
    set s = null
endfunction

private function Pause takes nothing returns boolean
    local unit u = GetFilterUnit ()
    call PauseUnit (u, true)
    return true
endfunction

private function Actions takes nothing returns nothing
    local rect r = GetPlayableMapRect()
    local group g = GetUnitsInRectAll(r)
    call GroupEnumUnitsInRect (g,r,functions Pause)
    call TriggerSleepAction( 2 )
    call ForForce( GetPlayersAllies(Player(10)), function team1win )
    call ForForce( GetPlayersAllies(Player(11)), function team2lose )
endfunction

//===========================================================================
private function InitTrig takes nothing returns nothing
    local team1 = CreateTrigger()
    call TriggerRegisterUnitEvent(team1, gg_unit_ofrt_0002, EVENT_UNIT_DEATH )
    call TriggerAddAction(team1, function Actions )
endfunction


JASS:
scope Ping initializer Init
   private function Actions takes nothing returns nothing // Private, so the name does not collide.
         local real x = GetUnitX(GetEnumUnit()) // Set the horizontal position of the unit.
                                                   // EnumUnit is JASS for 'Picked Unit'.
         local real y = GetUnitY(GetEnumUnit()) // Set the vertical position of the unit.
                                                  // Notice that the native is 'GetUnitY'.
         call PingMinimap(x,y,3.00)              // Pings the location where they interlap.
                                                        // This is faster than PingMinimapForForce(FORCE,x,y,3).
   endfunction

  private function Action2 takes nothing returns nothing
    local integer i = 'hpea'
    local group g = GetUnitsOfTypeIdAll(i)
    call ForGroup (g, function Actions)
    call DestroyGroup (g)
    set g = null
  endfunction

  function Init takes nothing returns nothing
       local trigger t = CreateTrigger()        // A local trigger is more 'portable'. (Acording to Vex.)
       call TriggerAddAction(t,function Actions)
      call TriggerRegisterTimerEventSingle( Ping, 10.00 )
  endfunction
endscope


the above script with BJs got turned into the bottom script, w/o BJs, obviously komaqtion did it for me...

JASS:
scope Ping initializer Init

    globals
        private constant string UNIT_NAME = "Peasant"
        
        private group ENUM = CreateGroup()
    endglobals

    private function EnumActions takes nothing returns boolean
        local unit u = GetFilterUnit()
        local real x = GetUnitX( u )
        local real y = GetUnitY( u )
        
        call PingMinimap(x,y,3.00)
        
        return false
    endfunction

    private function Actions takes nothing returns boolean
        call GroupEnumUnitsOfType( ENUM, UNIT_NAME, Filter( function EnumActions ) )
        
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterTimerEvent( t, 1.00, false )
        call TriggerAddCondition( t, Condition( function Actions ) )
    endfunction
    
endscope


and thats what i need to know.. how do i convert BJs into native functions

would i be asking too much if someone posted a list of all the BJs that are good to use and which ones aren't..
 

Executor

I see you
Reaction score
57
The best method is to code in the NewGen. There is a function list button, which opens a window, where you can enter the name of a function and by clicking on the function you get the source code.

The alternative would be http://wiki.thehelper.net/wc3/jass/Blizzard.j and search the bj you'd like to check with [ctrl + f].
 

Executor

I see you
Reaction score
57
komaqtion did the following things:
  • replaced TriggerRegisterTimerEventSingle with the native ("single"s are also native wrappers)
  • replaced the group create/destroy with one global group (there are tutorials out there to this topic)
  • replaced the 2 functions calls "GetEnumUnit()" with one call by using a local var
 

Romek

Super Moderator
Reaction score
964
My Tutorial covers this.
Search for "Natives and BJs".
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top