| 03-26-2007, 03:47 AM | #1 |
Mmm, I can't seem to get this to work. My thread crashs when I set my struct to an int handle. JASS:globals gamecache udg_loccache endglobals function H2I takes handle h returns integer return h return 0 endfunction function LocalVars takes nothing returns gamecache if udg_loccache == null then call FlushGameCache(InitGameCache("jasslocalvars.w3v")) set udg_loccache = InitGameCache("jasslocalvars.w3v") endif return udg_loccache endfunction function SetHandleInt takes handle subject, string name, integer value returns nothing if value==0 then call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name) else call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value) endif endfunction function GetHandleInt takes handle subject, string name returns integer return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name) endfunction JASS:globals constant integer chc_PROJID = 'h000' //Make this the unit you want as the //dummy projectile. constant real chc_PROJSPD = 400.00 //Speed of the dummy projectile. constant real chc_PROJRATE = .08 //Rate of the dummy projectile. endglobals struct blkrt_CHS unit u real ex real ey integer mt integer t endstruct function PointInRect takes rect r, real x, real y returns boolean if(x < GetRectMaxX(r) and x > GetRectMinX(r) and y < GetRectMaxY(r) and y > GetRectMinY(r))then return true endif return false endfunction function CH_Proj_Timer takes nothing returns nothing local timer t = GetExpiredTimer() local blkrt_CHS q = blkrt_CHS.create() local real x = GetUnitX(q.u) + q.ex local real y = GetUnitY(q.u) + q.ey set q = GetHandleInt(t, "cht.q") if(q.t >= q.mt)then call RemoveUnit(q.u) call PauseTimer(t) call DestroyTimer(t) set t = null endif if(PointInRect(GetPlayableMapRect(), x, y))then call SetUnitX(q.u, x) call SetUnitY(q.u, y) endif set q.t = q.t + 1 call SetHandleInt(t, "cht.q", q) endfunction function CrimsonHalo_Projectile takes player owner, real x, real y, real dist, real ang returns nothing local blkrt_CHS q = blkrt_CHS.create() local real rt = (chc_PROJSPD * chc_PROJRATE) local real r = dist / rt local timer t = CreateTimer() set q.u = CreateUnit(owner, chc_PROJID, x, y, 90) set q.ex = x + r * Cos(ang * bj_DEGTORAD) set q.ey = y + r * Sin(ang * bj_DEGTORAD) set q.mt = R2I(rt) set q.t = 0 call SetHandleInt(t, "cht.q", q) call BJDebugMsg("O_o") //Never displayed. call TimerStart(t, chc_PROJRATE, true, function CH_Proj_Timer) endfunction function Trig_Crimson_Halo_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local real x2 = GetOrderPointX() local real y2 = GetOrderPointY() local real x = GetUnitX(u) local real y = GetUnitY(u) local real sx = x2 - x local real sy = y2 - y local real dist = SquareRoot(sx*sx+sy*sy) local real ang = bj_RADTODEG * Atan2(y2 - y, x2 - x) call IssueImmediateOrder(u, "cancel") call CrimsonHalo_Projectile(GetOwningPlayer(u), x, y, dist, ang) endfunction Thread crashs at the highlighted part. Also, when my timer gets the handle, can I directly give my struct the handle or do I initialize it first then give it the struct handle? -Thanks -,-. |
| 03-26-2007, 03:50 AM | #2 |
JASS:globals gamecache udg_loccache=null endglobals |
| 03-26-2007, 03:53 AM | #3 |
*drools mindlessly* ... Wha? Why did that work? Guess I missed something in the tutorial O_o. Thanks, though. |
| 03-26-2007, 04:05 AM | #4 |
It is mostly that udg_loccache is not initialized. So SetHandleInt calls LocalVars which has an if then else that has udg_loccache == null as condition. But udg_loccache is not initialized (it should at least be null) so that if condition crashes. The best you could is library-fy your handle vars functions JASS:library HandleVarsIncomplete initializer init globals gamecache udg_loccache endglobals private function init takes nothing returns nothing call FlushGameCache(InitGameCache("jasslocalvars.w3v")) set udg_loccache = InitGameCache("jasslocalvars.w3v") endfunction function H2I takes handle h returns integer return h return 0 endfunction function LocalVars takes nothing returns gamecache return udg_loccache endfunction function SetHandleInt takes handle subject, string name, integer value returns nothing if value==0 then call FlushStoredInteger(udg_loccache,I2S(H2I(subject)),name) else call StoreInteger(udg_loccache, I2S(H2I(subject)), name, value) endif endfunction function GetHandleInt takes handle subject, string name returns integer return GetStoredInteger(udg_loccache, I2S(H2I(subject)), name) endfunction endlibrary |
