• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] bj_lastCreatedUnit vs GetLastCreatedUnit()

Status
Not open for further replies.
Level 18
Joined
Apr 13, 2008
Messages
1,629
Hi.
Using bj_lastCreatedUnit seems totally logical to me, but I see a lot of users using the GetLastCreatedUnit() instead. Is there a reason for that or they just simply make a mistake?

Another question is:
Do the bj_lastCreatedUnit and its counterparts (e.g.: bj_lastCreatedTimerDialog, etc) leak in BJs? Just because some BJs I checked do not clear the bj_lastWhatevers.

For example:
JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction

Thanks for the help.
 
The reason that some users use the GetLastCreatedUnit() is because they are noobs and don't know that this function actually do this:

JASS:
function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit // <= Doh!!!
endfunction

About your second question.... it would be nice to apply a good programming practice that is setting to null your variables before assigning a new value. To be clear: a variable will leak if and only if it's created and is not destroyed after being used.
 
Using bj_lastCreatedUnit seems totally logical to me, but I see a lot of users using the GetLastCreatedUnit() instead. Is there a reason for that or they just simply make a mistake?
Converted GUI, or newbs as Moyack said.

Another question is:
Do the bj_lastCreatedUnit and its counterparts (e.g.: bj_lastCreatedTimerDialog, etc) leak in BJs? Just because some BJs I checked do not clear the bj_lastWhatevers.
That makes no sense, seeing as the bj variables are globals.
 
no, really, defining global variables is quite possibly the simplest thing you can do... (its not even vJASS, all JASS Helper does is merge all global blocks in to a single one, as scripts are only supposed to have a single globals block.) It's even simpler than using the stupid ass GUI variable editor:
JASS:
globals
    // Syntax:
    [constant] <type> [array] <name> [= <value>]
    // Examples:
    constant real TIMER_TIMEOUT = 1 // the value of a constant can not be changed.
    integer PeonCount = 0 // a normal global which starts with a 0 value
    timer SpellTimer // Uninitialized. You must set a value to this variable before using it.
    unit array PlayerHeroes // You can not "= value" on an array.
endglobals
Note that initializing variables to some function will crash the game before it even finishes loading your map. don't do things like:
JASS:
globals
    unit Me = CreateUnit(...)
endglobals
 
Status
Not open for further replies.
Back
Top