BJs.

Exide

I am amazingly focused right now!
Reaction score
448
People keep telling me to get rid of BJs. Now I thought I'd do something about it, but I'm not quite sure how. :p

My first guess was to look up the Bj in JassCraft and see what it says, so this is what I get:

JASS:

//GetLastCreatedLightningBJ =

function GetLastCreatedLightningBJ takes nothing returns lightning
    return bj_lastCreatedLightning
endfunction


So I thought I'd just put that function above my actions, and change the function name.

JASS:

//Like so:

function LastEffect takes nothing returns lightning
    return bj_lastCreatedLightning
endfunction

//and then call for 
    set LightningEffect = LastEffect()


Now I get confused. The 'LastEffect' function contains a new bj? (return bj_lastCreatedLightning), what good does that do?

I figured I might as well search for that too and found:



..hmm. :confused:
What the heck is this? :p What do I do about it? Do I keep 'bj_lastCreatedLightning' in my 'LastEffect' function, or do I replace it with something else?
Am I doing this all wrong? :p

On top of it, almost every other BJ I can find develops the same way, and ends up confusing me. -As if conditions and loops weren't enough for me to handle..
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Well...BJ stands for blizzard jass...It is a damn anoying thing that it causes your maps engine to decode the code slower...

I'll take your example:
JASS:
//GetLastCreatedLightningBJ = 
function GetLastCreatedLightningBJ takes nothing returns lightning  
return bj_lastCreatedLightning 
endfunction

Since GetLastCreatedLightningBJ is as same as "bj_lastCreatedLightning" right?

In your situation...bj_lastCreatedLightning stands as a variable and it is NOT a BLIZZARD JASS...

You could straight:
JASS:
set bj_lastCreatedLightning = CreateLightning...


If you do like this:
JASS:
function LastEffect takes nothing returns lightning
    return bj_lastCreatedLightning
endfunction

Now the function "LastEffect" is as same as a BlizzardJass.

Since you uses a variable "LightningEffect" to create a lightning...You could really set the LightningEffect = CreateEffect bla bla bla...

You doesnt need to care about the bj_lastCreatedLightning...since it is the stupid GUI's code...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
> bj_lastCreatedLightning
> set LightningEffect = LastEffect()

You created a function to avoid having to call a function? ... Good job :p


set LightningEffect = bj_lastCreatedLightning

Better yet:
set LightningEffect = AddSpecialEffectLoc(...)
 

Exide

I am amazingly focused right now!
Reaction score
448
So, like this, then:

JASS:

    set LightningEffect = bj_lastCreatedLightning


Is that as optimized as it can be? Nothing else needs to be done there?
Why is it called bj_...? -That bothers me. :p

EDIT: Replied at about the same time as AceHart posted. :p

>Better yet:
set LightningEffect = AddSpecialEffectLoc(...)

-What's this all about?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Oh, yeah, lightning is not a special effect...


Anyway:
JASS:
function AddLightningLoc takes string codeName, location where1, location where2 returns lightning
    set bj_lastCreatedLightning = AddLightningEx(codeName, true, GetLocationX(where1), GetLocationY(where1), GetLocationZ(where1), GetLocationX(where2), GetLocationY(where2), GetLocationZ(where2))
    return bj_lastCreatedLightning
endfunction


When this function is called, is creates the lightning and stores it in the global variable.
That variable is, later on, returned by "GetLastCreated...".

Now, instead of passing through all of that mess, do it all yourself, in one line:

set myVariable = AddLightningEx(...)
 

Exide

I am amazingly focused right now!
Reaction score
448
EDIT:
I think I have realized that:

JASS:

native AddLightningEx               takes string codeName, boolean checkVisibility, real x1, real y1, real z1, real x2, real y2, real z2 returns lightning


Is like in GUI:

Code:
Lightning - Create a Forked Lightning lightning effect from source (Position of (Attacking unit)) to target (Position of (Attacked unit))

Where x1 and y1 is co-ordinates of (as in my case)(Position of (Attacking unit)), and x2 and y2 is; (Position of (Attacked unit)).
Is that correct?
I have yet to figure out what z1 and z2 is, though..
 

Arkan

Nobody rides for free
Reaction score
92
JASS:
local lightning lite = AddLightningEx('MBRN',true,x1,y1,z1,x2,y2,z2)

call DestroyLightning(lite)
set lite = null


codeName = the type of lightning, manaburn, shackles etc.
checkVisibility = not sure, I think whether it shows the lightning only if fog is visible or not

z1 & z2 = don't think these work, the intention was probably to make a lightning in any direction plane

set LightningEffect = AddSpecialEffectLoc(...)

As AceHart said before this doesn't work, Special Effect != Lightning Effect
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
the x1 y1 z1 and x2 y2 z2

1 represent the Attacking unit and 2 represent Attacked unit...(Case of your example)

You might use this though:
JASS:
1. GetUnitX(<unit>)
2. GetUnitY(<unit>)
3. GetUnitZ(<unit>)
 

Exide

I am amazingly focused right now!
Reaction score
448
Ok, so I got this:

JASS:

function Trig_Lightning_Effect_Conditions takes nothing returns boolean
    return ( ( GetUnitTypeId(GetAttacker()) == 'h000' ) )
endfunction

function Trig_Lightning_Effect_Actions takes nothing returns nothing
    local lightning LightningEffect
    local integer LoopStart = 1
    local integer LoopEnd = 2
    local real x = GetUnitX(GetAttacker())
    local real y = GetUnitY(GetAttacker())
    local real x2 = GetUnitX(GetAttackedUnitBJ())
    local real y2 = GetUnitX(GetAttackedUnitBJ())
    local real z
    local real z2
    loop
        exitwhen LoopStart > LoopEnd
        set LightningEffect = AddLightningEx( "FORK", true, x, y, x2, y2, z, z2)        
        call TriggerSleepAction( 0.50 )
        call DestroyLightning(LightningEffect)
        set LoopStart = LoopStart + 1
    endloop
    call PlaySoundAtPointBJ( gg_snd_LightningBolt, 90.00, GetUnitLoc(GetAttacker()), 0 )
endfunction

//===========================================================================
function InitTrig_Lightning_Effect takes nothing returns nothing
    set gg_trg_Lightning_Effect = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Effect, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lightning_Effect, Condition( function Trig_Lightning_Effect_Conditions ) )
    call TriggerAddAction( gg_trg_Lightning_Effect, function Trig_Lightning_Effect_Actions )
endfunction


Yes, I know I have another BJ to fix. I just wanted to ask if this looks allright?
I also wanted to state that adding 6 local variables to call one function doesn't seem smarter in any way, to me. But I guess I can't see the whole picture. :p
 

Exide

I am amazingly focused right now!
Reaction score
448

Exide

I am amazingly focused right now!
Reaction score
448
But that gives me three more BJs to worry about..
My trigger will change from maybe 20 lines to 60 lines, when I'm done with all the BJs.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>My trigger will change from maybe 20 lines to 60 lines
Well...for me...i would rather uses some BJ since they are more efficient to be...

Example will let you sees the truth:
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing


It's function is:
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction


Though it is a BJ...But we had no choise but to use it... :O
 

Exide

I am amazingly focused right now!
Reaction score
448
Ok, so I THINK I got this all sorted out now..
This is what my trigger looks like now:

JASS:

function Trig_Lightning_Effect_Conditions takes nothing returns boolean
    return ( ( GetUnitTypeId(GetAttacker()) == 'h000' ) )
endfunction

function Trig_Lightning_Effect_Actions takes nothing returns nothing
    local lightning LightningEffect
    local integer LoopStart = 1
    local integer LoopEnd = 2
    local real x = GetUnitX(GetAttacker())
    local real y = GetUnitY(GetAttacker())
    local real x2 = GetUnitX(GetTriggerUnit())
    local real y2 = GetUnitX(GetTriggerUnit())
    local real z
    local real z2
    local sound soundeffect = gg_snd_LightningBolt
    local location loc = GetUnitLoc(GetAttacker())
    local integer volume = 90
    loop
        exitwhen LoopStart > LoopEnd
        set LightningEffect = AddLightningEx( "FORK", true, x, y, x2, y2, z, z2)        
        call TriggerSleepAction( 0.50 )
        call DestroyLightning(LightningEffect)
        set LoopStart = LoopStart + 1
    endloop
    call SetSoundPosition(soundeffect, x, y, z)
    call SetSoundVolume(soundeffect, volume)
    call StartSound(soundeffect)
    call RemoveLocation(loc)
    set loc = null    
endfunction

//===========================================================================
function InitTrig_Lightning_Effect takes nothing returns nothing
    set gg_trg_Lightning_Effect = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Effect, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lightning_Effect, Condition( function Trig_Lightning_Effect_Conditions ) )
    call TriggerAddAction( gg_trg_Lightning_Effect, function Trig_Lightning_Effect_Actions )
endfunction


I haven't tested it yet, so I don't know if it works. :p
Tell me if you find any errors, or anything that can be changed.
Thanks for all the help. :)

EDIT: I tested it, and as I expected, nothing works. :p
No sound or lightning effects.. :(
 

Arkan

Nobody rides for free
Reaction score
92
You messed up the order of the arguments in AddLightningEx.

it's x, y, z, x2, y2, z2.

And try use 0 for z and z2.

And why create a location when you don't use it?
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>"FORK"
Who is teh fork?

IF it doesnt work on the sound...you may try using the BJ's
JASS:
    
call SetSoundPosition(soundeffect, x, y, z)
call SetSoundVolume(soundeffect, volume)
call StartSound(soundeffect)//removed these 3 lines and replace it with BJ's function...see if it work?
 

Sooda

Diversity enchants
Reaction score
318
> "FORK"

Stands for Forked Lightning effect. In our tutorial repository there is tutorial how to optimize your code aka getting rid of BJs.

> IF it doesnt work on the sound...you may try using the BJ's

If problem fix is to use BJs then you could stay to GUI triggering at first place, no need to start to do double work.
 

N-a-z-g-u-l

New Member
Reaction score
30
BJs dont instant-destroy your whole code, they only make the code about ~20% slower, if you use them... and some BJs are useful, for example the sound BJs might be...

(and i hate it when people are against BJs but use local handle vars, as local handle vars are about as useful as BJs... if you really need that performance, then use the gamecache itself... on your own, and not thorugh that system)

nevertheless, you should at least try to remove some BJs... like GetKillingUnit() instead of GetKillingUnitBJ()... but you wont feel a difference (except for if you post your code in a forum and everyone hates you for the BJs^^)
 

Exide

I am amazingly focused right now!
Reaction score
448
This thing is killing me. :p
I changed it a little, it's still not working, but I can see the lightning effects and hear the sounds, at least..
I believe z in this case would be some sort of co-ordinate, because the lightning effects only appear from north to south. They also appear beside the attacker. They don't start at the position of the attacking unit, and only go straight up (south-to-north degree).

JASS:

function Trig_Lightning_Effect_Conditions takes nothing returns boolean
    return ( ( GetUnitTypeId(GetAttacker()) == 'h000' ) )
endfunction

function Trig_Lightning_Effect_Actions takes nothing returns nothing
    local lightning LightningEffect
    local integer LoopStart = 1
    local integer LoopEnd = 2
    local real x = GetUnitX(GetTriggerUnit())
    local real y = GetUnitY(GetAttacker())
    local real x2 = GetUnitX(GetTriggerUnit())
    local real y2 = GetUnitX(GetTriggerUnit())
    local real z = 0
    local sound soundeffect = gg_snd_LightningBolt
    local integer volume = 90
    loop
        exitwhen LoopStart > LoopEnd
        set LightningEffect = AddLightning( "FORK", true, x, y, x2, y2)        
        call TriggerSleepAction( 0.50 )
        call DestroyLightning(LightningEffect)
        set LoopStart = LoopStart + 1
    endloop
    call SetSoundPosition(soundeffect, x, y, z)
    call SetSoundVolume(soundeffect, volume)
    call StartSound(soundeffect)
endfunction

//===========================================================================
function InitTrig_Lightning_Effect takes nothing returns nothing
    set gg_trg_Lightning_Effect = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lightning_Effect, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lightning_Effect, Condition( function Trig_Lightning_Effect_Conditions ) )
    call TriggerAddAction( gg_trg_Lightning_Effect, function Trig_Lightning_Effect_Actions )
endfunction


EDIT: Should sound effects be removed/nulled, or something?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top