HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What does BJ mean?

05-09-2004, 03:43 PM#1
qwertyui
There are some functions in Jass, which have BJ after their names. Like there is a function SubString, and there is a function SubStringBJ. Both BJ functions and their non-BJ counterparts take the same types of variables and return the same type of value.

What does BJ, appended to function's end, mean?
05-09-2004, 05:08 PM#2
PitzerMike
BJ-functions are functions in Blizzard.j that wrap the non-bj functions to be better usable in the UI of the world editor.

In your example the BJ function simply translates indizes meaning that in SubStringBJ the first letter is 1 where in the normal version the first letter is index 0. I'm not sure if it's extact like that but it is something similar.
05-09-2004, 09:29 PM#3
The Gearhead
So in SubStringBJ(Str,1,1) returns first letter? Rather than (Str,0,1)?

That's a lot more logical, IMO. Since there is no 0 letter. Heh.
05-09-2004, 10:21 PM#4
PitzerMike
When rethinking about it I guess it's not quite that.

I think SubString takes the first letter and the last letter
SubString("abcd",2,3) would then return "bc"

where SubStringBJ takes the first letter and the number of letters following so
SubString("abcd",2,3) would then return "bcd"

Again, I'm not quit sure, it's just something like that.
You can look into the SubStringBJ implementation in Blizzard.j to make sure this is true.
05-09-2004, 11:10 PM#5
Narwanza
Pitzer, they both take first and last letters, the difference is just that SubString works on a base 0 and SubStringBJ works on a base 1. I am not guarnteeing that this is exactly what the b.j says, but it is the same basic concept.

Code:
function SubStringBJ takes string s, integer start, integer end returns string
    return SubString(s,start-1,end)
endfunction

So SubString("abcd",2,3) would return "cd" (a = 0, b = 1, c = 2.....) And SubString("joe",1,1) returns either "" or null (can't remeber).

SubSringBJ("abcd",2,3) would return "bc" and SubStringBJ("abcd",1,1) would return "a".

Gearhead, I wouldn't expect such a statement out of you. Any programming language starts anything at 0 and just goes up. Blizzard really screwed a lot of things up when they decided to operate the GUI from a base 1. Not to mention the fact of all the time they spent writing a nearly useless 8000 lines of code just to make it work. Some of the BJ functions are nice, like ModInteger, but most are just a waste like SubStringBJ.
05-10-2004, 12:25 AM#6
The Gearhead
Yeah, so they should make it so that 0,0 calls letter 0. Not 0,1.

0,1 would make you think that since 0 is the first letter, then 1 would be the 2nd. But it's not.

In reality, this is how SubString works:

SubString([Str],[Index value of piece prior to starting letter],[Index value of last letter])

Ergo, if you want to return the first letter, you use 0,1. If you want to return the second letter, you use 1,2.

That makes no sense.

It should be, first letter is 0,0. Second is 1,1. And so on. So if I want to call a string that is 32 letters long, it should be: 0,31. Not, 0,32. 0,31 is 32 "indexes" and 0,32 is 33.

Since obviously I am not getting 33 letters, it should be 0,31.

Edit:
What do you mean 2,3 would return 2 letters?

I don't remember that occuring... ever.

I've always had to use a difference of 1 to call 1 letter. Difference between Start and Finish is the # of letters completed.

For example: 0,1 returns letter 1.
0,2 returns letter 1 and 2
0,3 returns letters 1, 2, and 3

You use subtraction to find the # of letters you will be getting, and then you add 1 to the start index (in this case 0) to find the first letter.

So, 2,3 means you start at letter 3, end at letter 3. You get letter 3.

SubStringBJ, the function used by the GUI, gives real indexes. 2,3 really means letter 2 through 3 inclusive.
05-10-2004, 02:27 AM#7
Narwanza
Sorry about the confusion there. I meant this.

SubString("abcd",2,4) returns "cd"

We all make mistakes.

Don't bash me for blizzard's incompetence to make logical natives. It isn't my fault that it isn't innovative for you. All I said was that everything starts at a base 0.
05-10-2004, 12:39 PM#8
The Gearhead
In SubString, the first digit starts at 0, the 2nd starts at 1.

So 0,1 is really (0, 1 - 1) or 0,0. So you have the first letter.

0,2 is 0,1, so its letter 0 and letter 1. Et cetera.

It's more logical when you use BJ which, I believe, gives precise numbers.

SubStringBJ("1234",1,4) gives letters 1 through 4

Who cares if it doesn't count at 0, in SubString they do count at 0... on half of it, at least.
05-10-2004, 01:43 PM#9
Vidstige
The logic, imho, with substringing is this: Normally, when counting indecis from 0 (which is a good idea since it gets screwed up if you store 2D arrays in an 1D array) it works like this: The first index says which is the first letter you are interested in, the second index says which is the first letter you are not interested in. It is like making two cuts in the string before the two indecis one specify, and then getting the part between the slices.

As far as I have noticed, the BJ functions wrapping the natives is mostly to make it mach the GUI behaviour. I try to avoid the BJ versions if possible, but that might just be a matter of taste...

Edit: This means that the natives count everything (?) from 0 and that the BJ fundtions often switches to 1 based indexing, which just confuses everything (imo).
05-10-2004, 03:16 PM#10
Cubasis
Yep,

The method SubString uses is also generally the propper one, used in most language API's (well, SubString funcs normally take a start index and length) in a way that it is 0-based and takes all characters too and not including end. That way if you want to take all the strings except the first char, you can do:

SubString(s,1,StringLength(s))

Atleast from past experience, this is logical to me.

Cubasis
05-11-2004, 05:08 AM#11
The Gearhead
That is correct.

However, I would have prefered that it used the length format, or double 0 indexing. 0,0 is letter 1, 0,1 is letter 1 and 2. When the first is greater than the second, it returns "". Oh well, you can't have everything go your way.