It's a couple of days now, that I've began learning Jass. I don't mind that is time consuming as long as things are done in the best, most effective and correct way, else what is the point using it? I'm a total noob, so please bear with me.
While trying to learn by improving/correcting my triggers, I've reached to this command:
Then I realized that:
1. It uses locations when I was in fact using reals and I had to convert the reals to points, then destroy the points, nullify them and so on.
2. The above function calls several others...Adding the unit to groups, saving it for later use as LastCreatedUnit etc...
SO, since I'm taking a shot on a Hero siege map that spawns thousands and thousands of units while continuously struggling to improve the speed of everything even slightly, it's only reasonable to try and use the native:
-I had to use a local variable (u) for the unit, so it can be used instead of LastCreatedUnit. If there is another way, please share.
-I was surprised to see that the native worked, even though udg_Hero_Type is not a unit but unit-type variable.
I'll paste the code, in case someone spots something I should know. Excuse my ignorance on writing/pasting code, I tried to make it as much readable as possible.
Now, here it comes the problem.
QUESTION 1. It seems logical that I should nullify the (u) local variable each time is used in the loop...
or it's ok if I just null it at the end just like the (p) variable?
Note: I know that this can be used directly:
to avoid the nullification of the local variable(u) but no matter that in this case the unit needs to be stored, in most other cases, it doesn't
This quote is taken from a tutorial I've been reading and it has greatly confused me.
I don't want the (u) unit to be instantly removed, that is why I store it at a global variable.
Generally, leak handling in GUI is different from that of JASS and I fail to deeply understand it yet, since I haven't found a tutorial that explains everything in detail. They tend to give an example and make reference of what else is similar.
QUESTION 2. Following through the functions after call CreateNUnitsAtLoc, I didn't see any nullification of the unit saved in bj's or any destroying of the bj_groups but I guess, there must be something for it internally... Is there?
QUESTION 3. If there is, can we directly use:
And avoid creating a local, or nullifying it?
Thanks for taking the time to read all this, I would appreciate any feedback on what asked or not.
While trying to learn by improving/correcting my triggers, I've reached to this command:
Code:
call CreateNUnitsAtLoc
Then I realized that:
1. It uses locations when I was in fact using reals and I had to convert the reals to points, then destroy the points, nullify them and so on.
2. The above function calls several others...Adding the unit to groups, saving it for later use as LastCreatedUnit etc...
SO, since I'm taking a shot on a Hero siege map that spawns thousands and thousands of units while continuously struggling to improve the speed of everything even slightly, it's only reasonable to try and use the native:
Code:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
set u=CreateUnit(Player(8),udg_Hero_Type[ri],x,y,180 )
-I had to use a local variable (u) for the unit, so it can be used instead of LastCreatedUnit. If there is another way, please share.
-I was surprised to see that the native worked, even though udg_Hero_Type is not a unit but unit-type variable.
I'll paste the code, in case someone spots something I should know. Excuse my ignorance on writing/pasting code, I tried to make it as much readable as possible.
Code:
function Trig_Random_Mode_Actions takes nothing returns nothing
local player p=GetOwningPlayer(GetSoldUnit())
local integer pn=GetConvertedPlayerId(p)
local unit u
local integer i=1
local integer ri
local real x
local real y
local effect sfx1
if ( Trig_Random_Mode_Func005C() ) then
call ClearSelectionForPlayer( p )
set udg_PickHeroCheck[pn] = (udg_PickHeroCheck[pn]-1)
set x=9023.8
set y=-7354.8+( 1154.50 * ( I2R(pn) - 1 ) )
call CreateUnit(p,'n00W',x,y,180 )
call AddUnitToStock(udg_Portal_Chance[pn], 'h00O', 1, 1)
call AddUnitToStock( udg_Portal_Chance[pn],'h00M', 1, 1 )
call AddUnitToStock( udg_Portal_Chance[pn],'h00N', 1, 1 )
call SetUnitAnimation( udg_Portal_Chance[pn], "birth" )
call CameraSetupApplyForPlayer( true, udg_CameraPick[pn], p, 2.00 )
set x=9281
set y=-7870+(1151.00 * ( I2R(pn) - 1 ) )
loop
exitwhen i > 3
set ri=GetRandomInt(100*i+1, 100*i+1+udg_Count[100*i])
set y=y+255
set sfx1=AddSpecialEffect("Abilities\\Spells\\Human\\Resurrect\\ResurrectCaster.mdl", x,y)
call DestroyEffect(sfx1)
set u=CreateUnit(Player(8),udg_Hero_Type[ri],x,y,180 )
set udg_Hero_Type[pn+i*10] = udg_Hero_Type[ri]
set udg_Temp_Units[100*i+pn] = u
set u=null
set sfx1=null
set i = i + 1
endloop
call TriggerSleepAction( 1 )
call SelectUnitForPlayerSingle( udg_Portal_Chance[pn],p )
else
call ClearSelectionForPlayer( p )
call DisplayTextToPlayer(p,0,0, "TRIGSTR_014")
endif
set p=null
endfunction
Now, here it comes the problem.
QUESTION 1. It seems logical that I should nullify the (u) local variable each time is used in the loop...
or it's ok if I just null it at the end just like the (p) variable?
Note: I know that this can be used directly:
Code:
set udg_Temp_Units[100*i+pn]=CreateUnit(Player(8),udg_Hero_Type[ri],x,y,180 )
You must never nullify local variables BEFORE you destroyed what they contained, or else you'll never be able to remove that.
An example of that error is like this:
Code:Custom script: set Exploding_Unit = null Custom script: call RemoveUnit( Exploding_Unit )
This quote is taken from a tutorial I've been reading and it has greatly confused me.
I don't want the (u) unit to be instantly removed, that is why I store it at a global variable.
Generally, leak handling in GUI is different from that of JASS and I fail to deeply understand it yet, since I haven't found a tutorial that explains everything in detail. They tend to give an example and make reference of what else is similar.
QUESTION 2. Following through the functions after call CreateNUnitsAtLoc, I didn't see any nullification of the unit saved in bj's or any destroying of the bj_groups but I guess, there must be something for it internally... Is there?
QUESTION 3. If there is, can we directly use:
Code:
set bj_lastCreatedUnit = CreateUnit(Player(8),udg_Hero_Type[ri],x,y,180 )
Thanks for taking the time to read all this, I would appreciate any feedback on what asked or not.