HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

jass editing / optimizing

11-01-2007, 04:10 AM#1
legend_tisman
I need someone to do a little coding. Most of the code is provided it just needs to be modified...
Reading the known jass bugs I found this...
Quote:
Originally Posted by cohadar
Expand JASS:
And this is my current code. It works except for some of the units ignoring the attack move order. I need the concept of the above solution added to this code. Pointing out / fixing leaks is much appreciated also.
Expand JASS:
My latest code with the help of Silvenon =) [+rep]
Expand JASS:
11-01-2007, 10:52 AM#2
Silvenon
If you need optimizing, then I'm your man.

call TriggerRegisterTimerEventPeriodic( gg_trg_Attack_Lowest, 30.00 )

Is a BJ, and it's equal to:

TriggerRegisterTimerEvent( gg_trg_Attack_Lowest, 30.00, true )

There's a leak here:

call ForGroupBJ( GetUnitsOfPlayerAll(Player(11)), function Trig_Attack_Command )

You have two options:
  1. Use bj_wantDestroyGroup + ForGroupBJ
  2. Store group in a variable + ForGroup + Destroy it and set it to null afterwards
I will demonstrate both ways:

First

Collapse JASS:
function Trig_Attack_Lowest_Actions takes nothing returns nothing
    // ...
    // ...
    // ...
    set bj_wantDestroyGroup = true
    ForGroupBJ( GetUnitsOfPlayerAll(Player(11)), function Trig_Attack_Command )
endfunction

Second

Collapse JASS:
function Trig_Attack_Lowest_Actions takes nothing returns nothing
    // ...
    local group g = GetUnitsOfPlayerAll(Player(11))
    // ...
    // ...
    // ...
    call ForGroup( g, function Trig_Attack_Command )
    call DestroyGroup(g)
    set g = null
endfunction

And GetUnitsOfPlayerAll is a BJ, that line could be written like this:

Collapse JASS:
// ...
local group g = CreateGroup()
call GroupEnumUnitsOfPlayer(g, Player(11), null)
ForGroup (g, ...)
//...

GetPlayersAll is also a BJ and it returns bj_FORCE_ALL_PLAYERS
You have a leak here:

call IssuePointOrderLocBJ( GetEnumUnit(), "attack", GetUnitLoc(udg_Hero[21]) )

But first we can make that a native:

IssuePointOrderLoc( GetEnumUnit(), "attack", GetUnitLoc(udg_Hero[21]) )

Because it does the same bloody thing anyways, it's just faster. GetUnitLoc(udg_Hero[21] is a leak, you need to store it in a location variable, and then destroy it and set it to null afterwards:

Collapse JASS:
function Trig_Attack_Command takes nothing returns nothing
    local location l = GetUnitLoc(udg_Hero[21])
    call IssuePointOrderLocBJ( GetEnumUnit(), "attack", l )
endfunction
    call RemoveLocation(l)
    set l = null
endfunction

This is also crap:

GetUnitStateSwap(UNIT_STATE_LIFE, udg_Hero[D])

Better use a native instead of those swap BJs:

GetUnitState(udg_Hero[D], UNIT_STATE_LIFE)
11-01-2007, 09:00 PM#3
legend_tisman
I tried combining the code and this is what i came up with...
Expand JASS:
I want to make sure what I did was correct.
And a quick question, Are all BJ's bad?
11-01-2007, 11:17 PM#4
Pyrogasm
The most of them are pointless functions like so:
Collapse JASS:
function IsUnitHiddenBJ takes unit whichUnit returns boolean
    return IsUnitHidden(whichUnit)
endfunction
While a select few are useful (multiboards in particular):
Collapse 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
Collapse JASS:
function MultiboardSetItemStyleBJ takes multiboard mb, integer col, integer row, boolean showValue, boolean showIcon returns nothing
    local integer curRow = 0
    local integer curCol = 0
    local integer numRows = MultiboardGetRowCount(mb)
    local integer numCols = MultiboardGetColumnCount(mb)
    local multiboarditem mbitem = null

    // Loop over rows, using 1-based index
    loop
        set curRow = curRow + 1
        exitwhen curRow > numRows

        // Apply setting to the requested row, or all rows (if row is 0)
        if (row == 0 or row == curRow) then
            // Loop over columns, using 1-based index
            set curCol = 0
            loop
                set curCol = curCol + 1
                exitwhen curCol > numCols

                // Apply setting to the requested column, or all columns (if col is 0)
                if (col == 0 or col == curCol) then
                    set mbitem = MultiboardGetItem(mb, curRow - 1, curCol - 1)
                    call MultiboardSetItemStyle(mbitem, showValue, showIcon)
                    call MultiboardReleaseItem(mbitem)
                endif
            endloop
        endif
    endloop
endfunction
11-02-2007, 02:12 AM#5
Ammorth
Multiboard BJs are horrible. It is better to make your own than use theirs (all the loops). And it is better still to use the natives directly in the code.
11-02-2007, 08:08 AM#6
zen87
Yup... instead, the natives for multiboard are much more easier to use than the BJs.
Quote:
And a quick question, Are all BJ's bad?
From what I've seen so far, not all of it are bad, just 99.999% of it :)
11-02-2007, 09:06 AM#7
Silvenon
Quote:
Originally Posted by Ammorth
Multiboard BJs are horrible.

Amen! I'm glad somebody shares my vision.

You can just nullify in the end, it's more organized that way.

You still didn't replace IssuePointOrderLocBJ with IssuePointOrder, it's easy to replace, I think even the parameters aren't mixed up.

Quote:
Originally Posted by Pyrogasm
Collapse 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

This almost doesn't make a difference at all, this happens once, and it's not that big of a deal if it's a BJ (though I replace that with natives anyways because I see BJs as evil. Even more with TESH, which makes them red)
11-02-2007, 02:06 PM#8
legend_tisman
Ok, i replaced the BJ for IssuePointOrder, and in takes X and Y not a Point/Location so I to get those values. I lso kind of renamed my variables for readablilty.
Expand JASS:

Edit: I am using shorter names for myself, I just figured it may help you guys out if I gave them full names.
11-02-2007, 02:53 PM#9
Silvenon
Name your variables with 2-3 letters max. (Location = l, Unit = u, Caster = c, Target = t, Timer = t.......). It's much easier to type and much faster (also the readability is better). Forget about the naming method you used for globals in GUI.
11-02-2007, 08:46 PM#10
legend_tisman
Is there a list of natives in world editor? When I write my code and I dont know what the line of code for the function is I make a new trigger get the gui function and convert it the use that line for what ever my purpose is.
eg. I need a units mana.
gui -> units mana -> convert to jass
= GetUnitStateSwap(UNIT_STATE_MANA, *)
add this line into my code and continue....

The problem is that appearantly gui always uses bj's and I dont know any natives. ( Well really I dont know most of the bjs either lol i just convert one when I need it)
11-02-2007, 10:00 PM#11
V@dim
Look for common.j in War3patch.mpq. It contains all native types.
11-03-2007, 06:47 AM#12
Pyrogasm
Either download JASSCraft or look here: http://82.170.159.98/?p=jass