• 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.

[JASS] Replacing some BJ's to good functions

Status
Not open for further replies.
Level 5
Joined
Dec 12, 2011
Messages
116
Okay, Magtheridon96 told me that all BJ's are bad because they are slow (except one that is something like TriggerRegisterAnyUnitEventBJ). So, I am creating a JASS script (actually, I started it through GUI and converted it to Custom Text). After conversion, I saw some BJ's there.

I made this with the intention to learn only. So, you guys will look to my function and say "wtf this function does nothing but waste memory". Yes, I just want to know how to replace those BJ's.

So, I want you guys to help me to improve this script:

JASS:
function insideItemLoop takes nothing returns nothing
    set udg_ItemArray[udg_tempInteger] = GetEnumItem()
    call SetItemVisible(GetEnumItem(), false)
    set udg_tempInteger = udg_tempInteger + 1
endfunction

function myFunc takes real x, real y returns nothing

    local rect itemRegion = RectFromCenterSizeBJ(Location(x,y), 100.00, 100.00)
    local integer counter = 0

    set udg_tempInteger = 0
    call EnumItemsInRectBJ( itemRegion, function insideItemLoop )
    call RemoveRect( itemRegion )
    set itemRegion = null

    loop
        exitwhen counter > udg_tempInteger
        call SetItemVisible(udg_ItemArray[counter], true)
        set counter = counter + 1
    endloop

endfunction

The RectFromCenterSizeBJ comes from the GUI function Region - Convert point with size to region
The EnumItemsInRectBJ comes from the GUI function Item - Pick every Item in Region and do (Actions)

By the way, I am not sure if this part of the forum is the right place to post this.

hamsterpellet
 
Level 6
Joined
Apr 16, 2011
Messages
158
Ok, if you don't have installed Jassnewgen, I suggest that you make the download and configure.
I suppose that you already have a location x and y
with the newgen it presses the key "ctrl" and click in BJ RectFromCenterSizeBJ
the following window will appear:
JASS:
function RectFromCenterSizeBJ takes location center, real width, real height returns rect
    local real x = GetLocationX( center )
    local real y = GetLocationY( center )
    return Rect( x - width*0.5, y - height*0.5, x + width*0.5, y + height*0.5 )
endfunction
and you have the following line:
local rect itemRegion = RectFromCenterSizeBJ(Location(x,y), 100.00, 100.00)

now it is enough you to adjust what you have in his bj for his native
like you already has something using x/y will define this way:

JASS:
    local real xx = GetLocationX( x) //x that you have
    local real yy = GetLocationY( y) // y that you have
    Rect( xx - width*0.5, yy - height*0.5,xx + width*0.5, yy + height*0.5 )
now we will arrange width and height

JASS:
    local real xx = GetLocationX( x) //x that you have
    local real yy = GetLocationY( y) // y that you have
    Rect( xx - 100.00*0.5, yy - 100.00*0.5, xx + 100.00*0.5, yy + 100.00*0.5 )
-
call EnumItemsInRectBJ( itemRegion, function insideItemLoop )
again press ctrl and click in the bj
and had appeared that:
JASS:
function EnumItemsInRectBJ takes rect r, code actionFunc returns nothing
    call EnumItemsInRect(r, null, actionFunc)
endfunction
as before, just to organize what you had in Bj to the native
call EnumItemsInRect(itemRegion, null, function insideItemLoop)

in the end everything was like this:
if I made something wrong somebody corrects
JASS:
function insideItemLoop takes nothing returns nothing
    set udg_ItemArray[udg_tempInteger] = GetEnumItem()
    call SetItemVisible(GetEnumItem(), false)
    set udg_tempInteger = udg_tempInteger + 1
endfunction

function myFunc takes real x, real y returns nothing
    local real xx = GetLocationX( x )
    local real yy = GetLocationY( y )
    local integer counter = 0
    local rect itemRegion = Rect( xx - 100.00 * 0.5, yy - 100.00 * 0.5, xx + 100.00 * 0.5, yy + 100.00 * 0.5 )

    set udg_tempInteger = 0
    call EnumItemsInRect(itemRegion, null, function insideItemLoop)
    loop
        exitwhen counter > udg_tempInteger
        call SetItemVisible(udg_ItemArray[counter], true)
        set counter = counter + 1
    endloop
    call RemoveRect(itemRegion)
    set itemRegion = null
endfunction
 
Last edited:
Level 5
Joined
Dec 12, 2011
Messages
116
Thaaaankss!!!!! (=
+rep to you man.

And by the way:

By installing JassNewGen:
- I will be able to use vJass?
- I won't be able to use GUI anymore?
- I will be able to return things back to non-JassNewGen if I want? I mean, easy uninstalll?
- Things in my maps will get messed?
- I will need to modify my JASS custom scrips to vJASS' ones?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
But to be clear, actually the JNGP has some issues with "recent" GUI addons, related to hashtable and handles (and more ?!).
I mean it won't crash or something like that, you will just be unable to use them totally like with the official editor.
Well, that's already the case, comparing jass and GUI features, anyway :p
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well any trigger-event function is not going to really matter, since they should all only be called once (with the exception of a damage-detection engine).

Everything beyond that should be reduced to a minimal amount of function calls (which means we need to get rid of BJs). Also keep in mind that you don't want everything to be in a single function, because that would destroy readability and maintainability.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
The GUI works, but it is an old version of the GUI that does not offer some of the new features that the new version does. I'm not sure if there are any circumstances in which normal use of the GUI would cause the editor to crash.
 
Status
Not open for further replies.
Top