| 10-22-2007, 04:48 AM | #1 |
I'm trying to get a launch trigger working. It should be moving any entering peasant unit 2 and a half terrain blocks, but does nothing instead. The codes a little woven, probably why I can't figure what's wrong: I beileive the problem lies in the timer function (ControlledLaunch), but I can't be sure. JASS:struct LAUNCHSTRUCT unit origin trigger trg endstruct globals LAUNCHSTRUCT array CLAUNCHS integer CLAUNCHn = 0 endglobals function RemoveLauncher takes unit u returns integer local integer I = 0 loop if(CLAUNCHS[i].origin == u)then call ResetTrigger(CLAUNCHS[i].trg) call DestroyTrigger(CLAUNCHS[i].trg) call RemoveUnit(CLAUNCHS[i].origin) set CLAUNCHS[i].trg = null set CLAUNCHS[i].origin = null call CLAUNCHS[i].destroy() return 1 endif exitwhen(I >= CLAUNCHn) set I = I + 1 endloop return -1 endfunction struct CLAUNCHEDSTRUCT unit lu real fac real dis real mdis endstruct globals CLAUNCHEDSTRUCT array CLAUNCHEDUNITS integer CLAUNCHEDUNITSn = 0 timer CLAUNCHEDTimer = CreateTimer() endglobals function ControlledLaunch takes nothing returns nothing local integer a = 0 local CLAUNCHEDSTRUCT cl local integer b = 0 loop set cl = CLAUNCHEDUNITS[a] if(cl.dis >= cl.mdis)then set CLAUNCHEDUNITS[a] = CLAUNCHEDUNITS[CLAUNCHEDUNITSn-1] set CLAUNCHEDUNITSn = CLAUNCHEDUNITSn - 1 call PauseUnit(cl.lu, false) set PInfo[GetPlayerId(GetOwningPlayer(cl.lu))].fly = false call cl.destroy() else call SetUnitX(cl.lu, GetUnitX(cl.lu) + 32. * Cos(cl.fac * bj_DEGTORAD)) call SetUnitY(cl.lu, GetUnitY(cl.lu) + 32. * Sin(cl.fac * bj_DEGTORAD)) set cl.dis = cl.dis + 32. endif exitwhen(a >= CLAUNCHEDUNITSn) set a = a + 1 endloop if(CLAUNCHEDUNITSn <= 0)then call PauseTimer(CLAUNCHEDTimer) endif endfunction function ObjectPallete_ControlledLaunch_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local LAUNCHSTRUCT l = GetCachedInt(GetTriggeringTrigger()) local CLAUNCHEDSTRUCT cl = CLAUNCHEDSTRUCT.create() set cl.lu = u set cl.fac = GetUnitFacing(l.origin) set cl.dis = 0 set cl.mdis = 320 if(GetUnitTypeId(u) == PUNITYPEID)then call PauseUnit(u, true) set PInfo[GetPlayerId(GetOwningPlayer(u))].fly = true set CLAUNCHEDUNITS[CLAUNCHEDUNITSn] = cl if(CLAUNCHEDUNITSn == 0)then call TimerStart(CLAUNCHEDTimer, .03, true, function ControlledLaunch) endif set CLAUNCHEDUNITSn = CLAUNCHEDUNITSn + 1 endif endfunction function ObjectPallete_ControlledLaunch takes unit u returns nothing local trigger t = CreateTrigger() local LAUNCHSTRUCT l = LAUNCHSTRUCT.create() set l.origin = u set l.trg = t call CacheInt(t, l) call TriggerRegisterUnitInRange(t, u, 128, null) call TriggerAddAction(t, function ObjectPallete_ControlledLaunch_Actions) set CLAUNCHS[CLAUNCHn] = l set CLAUNCHn = CLAUNCHn + 1 endfunction Thanks for any help, damn bugs -,-. |
| 10-22-2007, 07:45 AM | #2 |
The code is a little hard to read, I don't see the problem now, I'll check it up later. Btw, you're going for the single-timer method, right? So where do you pause the timer then? |
| 10-22-2007, 10:33 AM | #3 |
Yeah the code is decently hard to read, it's worse when it's woven between other function though >.>. Probably not helping me any. Code:
if(CLAUNCHEDUNITSn <= 0)then call PauseTimer(CLAUNCHEDTimer) endif The pause is in the ControlledLaunch function after the loop section. I'm still not quite sure what's wrong, it just refuses to move. I'm going through with BJDebugMsg's but I still can't find the problem. |
| 10-22-2007, 08:48 PM | #4 |
Maybe you could check in each function is the unit that is supposed to move equal to null. Have you determined anything with BJDebugMsg? Btw: JASS:function ObjectPallete_ControlledLaunch takes unit u returns nothing local trigger t = CreateTrigger() local LAUNCHSTRUCT l = LAUNCHSTRUCT.create() set l.origin = u set l.trg = t call CacheInt(t, l) call TriggerRegisterUnitInRange(t, u, 128, null) call TriggerAddAction(t, function ObjectPallete_ControlledLaunch_Actions) set CLAUNCHS[CLAUNCHn] = l set CLAUNCHn = CLAUNCHn + 1 endfunction It's better to do it like this: JASS:function ObjectPallete_ControlledLaunch takes unit u returns nothing local LAUNCHSTRUCT l = LAUNCHSTRUCT.create() set l.origin = u set l.trg = CreateTrigger() call CacheInt(t, l) call TriggerRegisterUnitInRange(l.trg, u, 128, null) call TriggerAddAction(l.trg, function ObjectPallete_ControlledLaunch_Actions) set CLAUNCHS[CLAUNCHn] = l set CLAUNCHn = CLAUNCHn + 1 endfunction You had a nulling leak anyways. |
