The function main is the function generated by the world editor.
It's the function which is run the first and call all the others init.
Btw it can be custom easily with the jasshelper.
function main() -> InitBlizzard() ->InitMapRects()
function InitMapRects takesnothingreturnsnothing set bj_mapInitialPlayableArea = Rect(GetCameraBoundMinX()-GetCameraMargin(CAMERA_MARGIN_LEFT), GetCameraBoundMinY()-GetCameraMargin(CAMERA_MARGIN_BOTTOM), GetCameraBoundMaxX()+GetCameraMargin(CAMERA_MARGIN_RIGHT), GetCameraBoundMaxY()+GetCameraMargin(CAMERA_MARGIN_TOP)) set bj_mapInitialCameraBounds = GetCurrentCameraBoundsMapRectBJ() endfunction
For the smallest map possible, 32*32 :
So calculate yourself how many iterations your loop will do, it's pretty huge...
This is a small dummy recycling system i made (took 10 min),its just a simple stack of units and very easy to use. any suggestions or idéa's are welcome :)
Dummy Recycling
library DummyRecycling initializer Init
globals privateconstantreal WAIT_TIME = 1. //time to wait before "removing" a dummy privateconstantinteger Dummy_id = 'hfoo'//dummy rawcode privateconstantinteger ARRAY_SIZE = 20 //Max Number of Dummy's (u dont need so many) privateunitarray Dummys [ARRAY_SIZE] privateinteger Total = 0 privateinteger Index = 0 endglobals
function CreateDummy takesplayer P, real x,real y returnsunit if Total < ARRAY_SIZE then// if the stack isnt full we create or move a unit if Index >= Total then//if there no free units we create more set Dummys[Index] = CreateUnit(P,Dummy_id,x,y,0.) call UnitRemoveAbility(Dummys[Index],'Amov') set Total = Total + 1 set Index = Index + 1 else//else we move one call SetUnitX(Dummys[Index],x) call SetUnitY(Dummys[Index],y) call SetUnitOwner(Dummys[Index],P,false) set Index = Index + 1 endif return Dummys[Index-1] debugelse debugcall BJDebugMsg("To many dummy's, increase the ARRAY_SIZE") endif
returnnull endfunction
function CreateDummyLoc takesplayer P, location loc returnsnothing call CreateDummy(P,GetLocationX(loc),GetLocationY(loc)) call RemoveLocation(loc) set loc = null endfunction
function ReleaseDummy takesunit u returnsnothing//this just change the owner of the dummy (maybe we should move them some where?) if GetUnitTypeId(u) == Dummy_id then call TriggerSleepAction(WAIT_TIME)//maybe use a timer instead? call SetUnitOwner(u,Player(15),false) set Index = Index - 1 debugelse debugcall BJDebugMsg("function RemoveDummy: Unit given is not a Dummy Unit") endif endfunction
privatefunction Init takesnothingreturnsnothing set Dummys[Index] = CreateUnit(Player(15),Dummy_id,0.,0.,0.) call UnitRemoveAbility(Dummys[Index],'Amov') set Total = Total + 1 endfunction
endlibrary
e.g of usage
set Temp = CreateDummy(GetOwningPlayer(GetTriggerUnit(),0.,0.) //dummy stuff call ReleaseDummy(Temp)
well im in a rush so can't write more (ill get back later)
I don't really get why one would need a dummy recycling system, if you think about it, you only ever need the amount of units to be used when they are used, holding more just uses space, like a leak.
Unless it takes more memory to create unit than it does to run all of those functions to store an already created one, I really don't know, but I feel like the memory usage is from the presence of the unit, not its coming into usage.
EDIT - Something I just thought up, used for calling code without using TriggerEvaluate(), while avoiding constantly destroying the triggers you use
library CallCode globals privatetrigger T = CreateTrigger() privateconditionfunc C privateboolean B endglobals function CallCode takescode c returnsboolean set C = TriggerAddCondition(T, Condition(c)) set B = TriggerEvaluate(T) call TriggerRemoveCondition(C) return B endfunction endlibrary
here is a little function, probably leaked because i am a noob but works ingame perfectly, removes a unit in a period of time like native UnitApplyTimedLife... this function's proper way to use is after death of an unit to clean it faster for example whenever death animation ends of an special effect dummie unit so you don't have to use buggy waits. (pause game doesn't affect waits)
Requieres handle vars
function RemoveUnitTimer takesnothingreturnsnothing localtimer T = GetExpiredTimer() localunit U = GetHandleUnit(T, "u") localreal duration = GetHandleReal(T, "dur") if duration > 0.05 then call SetHandleReal(T,"dur", duration-0.05) else call RemoveUnit(U) call FlushHandleLocals(T) endif endfunction function AddRemoveUnitTimer takesunit U, real duration returnsnothing localtimer T = CreateTimer() call SetHandleReal(T,"dur", duration) call SetHandleHandle(T,"u", U) call TimerStart(T,0.05,true, function RemoveUnitTimer) set T = null endfunction
If you create a locusted unit at (x, y), the unit will consider pathing (as if it didn't have locust) (EDIT: at the moment of its creation). This can be avoided by moving the unit with SetUnitX/Y right after.
Like, if you had a projectile that had locust, and then sent it on its path without using the X/Y, the locust would move all f*cked up when it got to a cliff or something, but if you first use the X/Y, then it will do it cleanly?
(I don't have war3 isntalled on this comp, but I would very very much appreciate somebody checking that for me)
Like, if you had a projectile that had locust, and then sent it on its path without using the X/Y, the locust would move all f*cked up when it got to a cliff or something, but if you first use the X/Y, then it will do it cleanly?
I tried to create a unit with locust at the position of a normal unit, but the locusted unit appeared on the side of it, not 'inside' it like it would if I had moved it there with SetUnitX/Y.
(forgot to mention in my earlier post that I was only talking about the moment of creation)
Errr, when would you need to check just one integer variable?
I think as a concept this is ok, but as code to be used, this isn't too useful as a debugging tool unless you could specify the array being checked, converting it to a textmacro may be helpful