HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Gui create units vs CreateUnitAtLoc()

08-17-2005, 10:58 PM#1
HexenLordX
I'm a wee bit of a JASS newb, but I realize that the GUI 'Create N Units' leaks a unit group each time it is used. Well that action is probably used THOUSANDS of times in my map, meaning I better do something about it.

I looked at the GUI function in my map script, it looks like this:
call CreateNUnitsAtLoc(1,'n00D',Player(12),udg_SpawnPoint[13],GetRandomReal(0,360))

So if I was to put in CreateUnitAtLoc(), would it look like this:
call CreateUnitAtLoc('n00D',Player(12),udg_SpawnPoint[13],GetRandomReal(0,360))

just making sure, I don't want to use it and have done it wrong.
08-18-2005, 12:19 AM#2
HexenLordX
I guess I'm gonna have to keep posting until I figure it out myself, eh?

Anyway, The GUI function looks like this:
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group

The JASS function 'CreateUnitAtLoc' looks like this:
native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit

I'm not exactly sure how to distinguish between 'player whichPlayer' and 'player id'. Anyone have examples?
08-18-2005, 07:21 AM#3
Anitarf
Quote:
Originally Posted by HexenLordX
I'm not exactly sure how to distinguish between 'player whichPlayer' and 'player id'. Anyone have examples?
Actualy, there is no difference. The type is the same, both functions take a player as an argument, they just name them differently, one names it "whichPlayer", the other one "id".

As you can see, CreateUnitAtLoc() has a slightly different order than CreateNUnitsAtLoc(), so this would be the proper code:

call CreateUnitAtLoc(Player(12),'n00D',udg_SpawnPoint[13],GetRandomReal(0,360))

Thousands of leaks is... well, it's bad, but you really have to get into hundreds of thousands to cause serious performance issues (well, I suppose it depends on the machine you're running the game on as well). Anyway, thousands is still something, so it's a good choice to clean them up.
08-18-2005, 11:22 AM#4
HexenLordX
Wow that helped out a lot! Thanks!
08-18-2005, 12:04 PM#5
EdwardSwolenToe
The BJ createNunits does not leak a group, it uses the global bj group variable each time.
08-18-2005, 12:30 PM#6
HexenLordX
Small problem. Heres one of my spawning triggers:

Jellybean
Events
Map initialization
Conditions
Actions
For each (Integer A) from 1 to 500, do (Actions)
Loop - Actions
Set JellyPoint[44] = (Random point in JellyBean <gen>)
Custom script: call CreateUnitAtLoc(Player(15),'n01E',udg_JellyPoint[44],GetRandomReal(0,360))
Animation - Change (Last created unit) flying height to (Random real number between 1.00 and 750.00) at 0.00
Point - Remove JellyPoint[44]
Trigger - Destroy (This trigger)

It appears you can't use (Last created unit) with a unit created with the Custom Script. :(
08-18-2005, 03:42 PM#7
oNdizZ
it should work. the only thing i can think of is that the 'n01E' unit isn't a flying unit -_^
08-18-2005, 04:12 PM#8
Anitarf
Quote:
Originally Posted by EdwardSwolenToe
The BJ createNunits does not leak a group, it uses the global bj group variable each time.
So? Does it destroy the group previously assigned to the bj variable before using it? Anyway, I didn't make this up, Lord Vexorian did, I remember him saying a few times that the GUI action to create units leaks.

Quote:
Originally Posted by HexenLordX
It appears you can't use (Last created unit) with a unit created with the Custom Script. :(
Are you sure? If it's true, then there's a simple workaround, all you need is an unused unit variable, in my example I'll call it tempUnit.

Custom script: set udg_tempUnit = CreateUnitAtLoc(Player(15),'n01E',udg_JellyPoint[44],GetRandomReal(0,360))
Animation - Change tempUnit flying height to (Random real number between 1.00 and 750.00) at 0.00
08-18-2005, 05:13 PM#9
HexenLordX
Quote:
Originally Posted by Anitarf
Quote:
Originally Posted by HexenLordX
It appears you can't use (Last created unit) with a unit created with the Custom Script. :(
Are you sure? If it's true, then there's a simple workaround, all you need is an unused unit variable, in my example I'll call it tempUnit.

Custom script: set udg_tempUnit = CreateUnitAtLoc(Player(15),'n01E',udg_JellyPoint[44],GetRandomReal(0,360))
Animation - Change tempUnit flying height to (Random real number between 1.00 and 750.00) at 0.00
[/quote]

Wouldn't that require me to make another global variable? BAH.
And yes I'm sure it doesn't work, it worked PERFECTLY before I changed the GUI into custom script.
08-18-2005, 10:18 PM#10
Vexorian
You shouldn't use CreateNUnitsLoc when you just want to create a unit, because you would be wasting unnecesary steps of the execution.

CreateNUnitsLoc does not leak a group it always uses the same group object pointed by the same global group variable.

BUT, GetLastCreatedUnitGroup() creates a new group object and adds the current units in the variable to the group it returns, that's how it works you should destroy the returned group once you don't need to use it anymore
08-18-2005, 11:26 PM#11
Anitarf
I see... sorry for the misinterpertation.