Tutorial The Good, The Bad, and The BJ

Sevion

The DIY Ninja
Reaction score
413
The Good, The Bad, and The BJ

By: Sevion

Contents

Introduction
What is a BJ?
What is a Native?
The Good
The Bad
Conclusion

I would make anchor tags, but they seem to have been removed.

Introduction

I am making this tutorial because there seem to be *many* misconceptions about them.

I.E.: "ZOMG! BJ! I ARE BURNING!!! AGH!!!!!!!!!!!"

Many people seem to believe that all BJ's are terrible and should be avoided at all costs. That cost usually ends up being code readability.

I hate always having to read loop loop loop.... loop.... loop.... or having a quadbillion calls just to do one thing.

Sure, it's an extra call.

ONE (usually) extra call.

Not exactly a lot.

Though, there are some BJ's that are just plain retarded.

Want to know more? Read on!​

What's a BJ?

A BJ is simply a function in the blizzard.j.

Simply put, it's a wrapper made by Blizzard to either make JASSing easier or make it easier to develop/shorter descriptions for the UI for GUI.

An example would be the swapped functions.

A BJ, in essence is a misunderstood tool.

It's like a double-bladed sword. It can both harm your code, and make it better.

It's merely a question of which BJ's to use and which to avoid.​

What is a Native?

A Native is a function programmed into Warcraft III already. They are all listed in the common.j.

All Natives are better than BJ's in terms of speed and efficiency, no arguments whatsoever.

However, BJ's are, in most cases, better for readability, and this can be used in favor over efficiency when it's not going to affect gameplay much or at all and when readability is a high priority.​

The Good

There are good BJ's.

Some are the BJDebugMsg. Yeah, that one is tehpwnagezorz.

BJDebugMsg is like Arnold Schwarzenegger yelling "GET TO DAH CHOPPAH!!!!!!!"

:)

Another few are the math ones like RMaxBJ.

Texttag functions are tehpwn as well if you've ever tried making them with Natives.... *shivers*

Some events like TriggerRegisterAnyUnitEventBJ are alright, though you can also use TriggerRegisterPlayerUnitEvent with GetLocalPlayer()

[PSST! HELP ME LOOK FOR A BJ THAT'S BETTER (efficiency) THAN A NATIVE! I will gets a cookie :)]​

The Bad

All Natives are faster than BJ's, however, who the hell can tell the difference between 0.0001 seconds of execution time and 0.0005 seconds?

Seriously?

If you can, you are not human.

BJ's are also very bad.

Consider <FunctionName>Swapped.

What's the point in that?

Well, Blizzard made them in mind that, one extra function call won't hurt and that it would be easier to make the text UI for GUI that way. Though, why they didn't just make the Native oriented that way, I don't know.

An example of this stupidity is:

JASS:
function SetUnitAbilityLevelSwapped takes integer abilcode, unit whichUnit, integer level returns integer
    return SetUnitAbilityLevel(whichUnit, abilcode, level)
endfunction


Seriously, what's the point in calling a function and having that function return a function?

It does nothing else!

All it does is change the orientation of your arguments!

So, while it helps making GUI texts, it's kind of retarded ;)

That, is a stupid thing to do.

Don't use those functions.

A good way to tell if you should or should not use a function is to check the function's code. If it looks retarded, it probably is.

If you're not sure, use the Native form. It's almost always going to be better.

But, BJ's are more safe. Blizzard made them failsafe(ish). If the Native is bugging for you, try the BJ and see what happens.​

Conclusion

What do I think?

Well, there are many pros and cons.

Let me line them up:

Pros:
  • Can be same speed (Keyword: Can)
  • Can have better readability

Cons:
  • Can have leaks
  • Will have less speed
  • Can make lag
  • Can teach bad habits (Keyword ;))
  • Can get flamed for using them :(
  • Can have worse readability [Yes, I have seen that before]

So, you're looking at this and going "Are you retarded? Cons wayyyyy outweigh the Pros!

Even so, if you know how to use them, you can cancel out a lot of the Cons.

It's all a matter of whether or not you know how to use them.

So learn.

I'm willing to bet some very experienced vJASS'ers may have something to learn here.

So, while it's true, BJ's should mostly be avoided, it depends on your situation ;)

The more you use BJ's in submitted resources etc, the more advice you'll receive and the more you'll know about which BJ's to use, when to use them etc.

So experiment!

Learn!

You will become a BJ master! (Oh, God. That sounds dirty :D)​

If there is anything I've missed or royally fucked up on, please tell me. I want to make this as accurate and informative as I can.​
 

_whelp

New Member
Reaction score
54
BJ master? Stop watching porno. Tutorial is good, but I'm only saying that because I skimmed quickly...
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I only got to the end of "The Good".
You're trying to teach that leaks aren't bad or :confused: ?
Sure, while one leak will not affect gameplay;
If these leaks pile up (Because people think 'eh, it won't do anything') then they have to go back through and redo their code.

As for your PolarProjection thing.
I actually find the native version easier to read :rolleyes: .

And I don't know exacts but;
Wouldn't calling upon that extra function also make the BJ slower?

Although I do agree that some BJ's are definitely useful:
CountUnitsInGroup(), TriggerRegisterAnyUnitEventBJ(), etc.
Either of those, IMO, would have made a better example.

Anyways;
It's really late here so I can't think of anymore :p .
Tomorrow once I get home from school I shall give this a better read-through.
 

Sevion

The DIY Ninja
Reaction score
413
Bleh. I wrote this on a whim :p

Tomorrow is last day of school. I'll revise then. XD

I wrote this in the span of 10 minutes :p
 

Hellohihi

New Member
Reaction score
42
Cool. +rep.

One very lame bj i found was:
GetAttackedUnitBJ calls GetTriggerUnit()......

Never knew what was behind the scenes when using GUI.
 

Sevion

The DIY Ninja
Reaction score
413
Told you some of them are retarded ;)

Most of those event responses have to do with GetTriggerUnit() :)

Trigger Unit is the unit who makes the trigger happen. So A unit is attacked will fire and the triggering unit is the attacked unit. As him being attacked caused the trigger to fire.
 

Exide

I am amazingly focused right now!
Reaction score
448
<Function>Swapped = Code to English.
For example the one you mentioned: 'SetUnitAbilityLevelSwapped'. (I don't have WE with me, so I don't remember it exactly, but you will get the idea.)
SetUnitAbilityLevelSwapped = Set *Ability* for *Unit* to *Level*. (Which is readable in English/GUI.)
If they would've used the native it would be: Set *Unit* for *Ability* to *Level*. (Don't make much sense.)
-Indeed, it is retarded when coding in JASS, but quite understandable when coding in GUI.

About PolarProjectionBJ, you're forgetting that PolarProjectionBJ returns location, not coordinates. Which is fine when coding in GUI, but I don't think I've ever seen a proper JASS spell trigger that uses locations instead of coordinates..
(You already mentioned the leak, so I won't bring that up.) ^^


EDIT:
One very lame bj i found was:
GetAttackedUnitBJ calls GetTriggerUnit()......

Never knew what was behind the scenes when using GUI.

-Which is why you should always use (Triggering Unit) when possible.
 

Romek

Super Moderator
Reaction score
964
JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD) // 2 calls
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD) // 2 calls
    return Location(x, y)
endfunction

And Location(x, y) isn't a call? :rolleyes:

Also, in that example:
JASS:
// u is a unit
local location loc = PolarProjectionBJ(u, 10, GetUnitFacing(u))

Syntax error. You need GetUnitLoc(u). Oh, wait. That's another damned function call! :p

Also, take into account that function calls are needed to remove the location leaks.
This isn't the case when using the 'natives'. (Cos and Sin directly, with x and y)

> [I'm going to get uber-flamed for that]
Fucking retard.

Also, about the Polar Projection. That's usually called many, many times in rapid succession. In which case, the Cos and Sin would be stored into variables. However, when using the BJ, this isn't an option. So not only is it slower as it is, but how much slower it really is begins to shine when put into real situations.

> using BJ's the same speed or even faster than Natives.
Give me an example, and you'll get a cookie.

Only the last Pro of BJs is correct. In rare cases. :p
The only good BJs are BJDebugMsg (very useful for debugging), and most of the Math ones. RMinBJ, RMaxBJ, etc.
They're actually useful, and certainly help with readability.
 

GooS

Azrael
Reaction score
154
You will become a BJ master! (Oh, God. That sounds dirty :D)

IRL laughing, well as for the tutorial, it could probably help some, but so could some extra thinking and logic.

SetUnitAbilityLevelSwapped = Set *Ability* for *Unit* to *Level*. (Which is readable in English/GUI.)
If they would've used the native it would be: Set *Unit* for *Ability* to *Level*. (Don't make much sense.)
-Indeed, it is retarded when coding in JASS, but quite understandable when coding in GUI.

Are the GUI functions (Bj's) forced to have those words in between?
Set *Unit*'s *Ability* to level *Level*
And we have a decent use of English, Set *Footmans*'s *Defend* to level *1*
But I've never checked for anything like that so,, hmm whatever


//==GooS
 

Romek

Super Moderator
Reaction score
964
> There exists only two noteable BJ functions:
How on earth is the latter any good? :p
 

Flare

Stops copies me!
Reaction score
662
Texttags are a b**** to create using natives only, so one may be inclined to use the BJ function. However you yourself can create a more efficient function than the one Blizzard made.
What about creating multiboards? Probably not as hard, but would be convenient to have the one line instead of bloating code with 5 or 6 lines ^_^

How on earth is the latter any good?
You don't have to input a weapon type, or the boolean parameters? :p

I still don't really know what the booleans for UnitDamageTarget do :D
 

Viikuna

No Marlo no game.
Reaction score
265
Allmost every map has somekind of custom DmageTarget function with nice boolean arguments, like considerArmor and maybe some custom damage types for dmage systems events and stuff like that.

( well, ok "has" is not quite true. "should have" is better. )

So I would guess that it is quite useless BJ.
 
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

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top