| 07-28-2008, 03:49 PM | #1 |
Hi guys, I have a problem I can't fix. Aparently, for me this code should work fine ... what should it do ? Well, When a unit enters a specific region (one of 6) text should start appearing on it, and 40 seconds after, the enetering unit should move on to another region, all this is a cicle. Problem is, that when 40 seconds pass, the unit starts moving to the next region (as expected) but than, when it reaches half of the trajectory, it just moves back to the region where it was before. I don't know the error, this code needs to be MUI and I think it is MUI, but I make no idea about why the damn stupid plan goes back again. please this is one of the major (most important) system of my map, I really need to find a solution for this and with urgency ! I'll give +rep to those who help =S JASS:scope PlaneBomber initializer Init globals constant integer PLANEID = 'h00N' //Id of the plane rect array planeRegions[6] //an array with all regions the plane will visit endglobals private struct MyStruct unit aPlane timer texter timer move integer regionNumber static method create takes unit thePlane returns MyStruct local MyStruct data = MyStruct.allocate() set data.aPlane = thePlane set data.texter = NewTimer() set data.move = NewTimer() set data.regionNumber = 0 return data endmethod method onDestroy takes nothing returns nothing call ReleaseTimer(.texter) call ReleaseTimer(.move) endmethod endstruct //============================================================ private function RandomText takes nothing returns string local integer i = GetRandomInt(0, 5) if (i == 0) then return "Become God Itself!" elseif (i == 1) then return "Super Armors and Swords!" elseif (i == 2) then return "Buy your Items here!" elseif (i == 3) then return "Fear no Enemy!" elseif (i == 4) then return "Great Power, Low Price!" elseif (i == 5) then return "Buy now, tax free!" endif return "Crash, Inform Flame_Phoenix" endfunction //============================================================ private function ShowText takes nothing returns nothing local MyStruct data = MyStruct(GetCSData(GetExpiredTimer())) local texttag text = CreateTextTag() call SetTextTagText(text, RandomText(), .023) call SetTextTagPos(text, GetUnitX(data.aPlane), GetUnitY(data.aPlane), 280) call SetTextTagColor(text, GetRandomInt(50, 255), GetRandomInt(50, 255), GetRandomInt(50, 255), 255) call SetTextTagPermanent(text, false) call SetTextTagVelocity(text, 0, .0277) call SetTextTagFadepoint(text, 1) call SetTextTagLifespan(text, 2.5) call SetTextTagVisibility(text, true) set text = null endfunction //=========================================================================== private function Move takes nothing returns nothing local MyStruct data = MyStruct(GetCSData(GetExpiredTimer())) call IssuePointOrder(data.aPlane, "move", GetRectCenterX(planeRegions[data.regionNumber + 1]), GetRectCenterY(planeRegions[data.regionNumber + 1])) call data.destroy() endfunction //=========================================================================== private function onCreate takes nothing returns boolean call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), PLANEID, GetRectCenterX(planeRegions[0]), GetRectCenterY(planeRegions[0]), 270.) call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), PLANEID, GetRectCenterX(planeRegions[3]), GetRectCenterY(planeRegions[3]), 270.) return false endfunction //=========================================================================== private function onEnter takes nothing returns boolean local unit u = GetTriggerUnit() // the entering unit local integer uID = GetUnitTypeId(u) local integer i = 0 local MyStruct data if (uID == PLANEID) then loop exitwhen (i == 6) if RectContainsUnit(planeRegions[i], u) then set data = MyStruct.create(u) //here we set the text and repeat it over and over again call SetCSData(data.texter, integer(data)) call TimerStart(data.texter, 2.5, true, function ShowText) call SetCSData(data.move, integer(data)) call TimerStart(data.move, 40., false, function Move) set data.regionNumber = i if (data.regionNumber == 5) then set data.regionNumber = -1 endif endif set i = i + 1 endloop endif return false endfunction //=========================================================================== private function Init takes nothing returns nothing local trigger BomberTrigger = CreateTrigger( ) //this trigger creates two stupid planes when time is 20 call TriggerRegisterTimerEvent(BomberTrigger, 20., false) call TriggerAddCondition(BomberTrigger, Condition(function onCreate)) //yes, this trigger keeps track of all this regions, and if a unit //enters one of them, the function is called correctly set BomberTrigger = CreateTrigger() call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_1 ) call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_2 ) call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_3 ) call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_4 ) call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_5 ) call TriggerRegisterEnterRectSimple( BomberTrigger, gg_rct_Boom_6 ) call TriggerAddCondition(BomberTrigger, Condition(function onEnter)) set BomberTrigger = null //setting our globals set planeRegions[0] = gg_rct_Boom_1 set planeRegions[1] = gg_rct_Boom_2 set planeRegions[2] = gg_rct_Boom_3 set planeRegions[3] = gg_rct_Boom_4 set planeRegions[4] = gg_rct_Boom_5 set planeRegions[5] = gg_rct_Boom_6 endfunction endscope |
| 07-28-2008, 03:56 PM | #2 |
First of all, as mentioned in some other places: Is Unit In Region might not return true in some cases, even though it should. It's better to attach CSData to the actual regions and check GetTriggeringRegion(). JASS:function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event local region rectRegion = CreateRegion() call RegionAddRect(rectRegion, r) return TriggerRegisterEnterRegion(trig, rectRegion, null) endfunction Stopping halfways sounds weird. Are the units Neutral / do they have a max distance before running back? Check if a unit of Player 1 (you) would act the same. |
| 07-28-2008, 04:33 PM | #3 |
You know OP you would save yourself a lot of time if you learned to fix your own problems. |
| 07-29-2008, 02:02 PM | #4 | ||
Quote:
Anyway, I will change it to player 1 to see what happens. Please explain me better the Region thing, and thx for your advice. Quote:
If that is about me, I know how to fix my problems, however there is no shame in asking for help to do so, and I know when I need it. Also, if you don't wanna help people, just don't post. |
| 07-29-2008, 03:07 PM | #5 | ||
Quote:
Original poster. Quote:
You think I posted that just to spite you? I was being completely serious. There is no shame in asking for help, but it is definitely not the best way to solve problems in general. Consider that the people viewing this thread will know much less about your trigger and its context than you, and they will also care a lot less about fixing your problem than you, and they won't have the world editor open with a good testing environment for your trigger. The most time efficient option is to develop a methodical process for isolating and fixing flaws. I usually place BJDebugMsg calls throughout problem code to see if everything is run correctly, if loops are terminating at the right time, if variables are set to the right thing, etc. This is a fairly reliable way to track down a problem. You could probably start by tracing the values of the rects in planeRegions and the value of data.regionNumber in the Move function. |
| 07-29-2008, 04:05 PM | #6 |
Here, you only have control of the rects. Let's transform your code into something which controls the regions: JASS:function onEnter takes nothing returns boolean local integer index = GetCSData( GetTriggeringRegion() ) //.... endfunction function Init takes nothing returns nothing //.... local region RegionVar=CreateRegion() call RegionAddRect(RegionVar, gg_rct_Boom_1) call SetCSData(RegionVar, 1) call TriggerRegisterEnterRegion( BomberTrigger, RegionVar, null ) set RegionVar=CreateRegion() call RegionAddRect(RegionVar, gg_rct_Boom_2) call SetCSData(RegionVar, 2) call TriggerRegisterEnterRegion( BomberTrigger, RegionVar, null ) //.... etc call TriggerAddCondition(BomberTrigger, Condition(function onEnter)) endfunction |
| 07-29-2008, 07:53 PM | #7 |
Mmm so you are saying that I have to write this: JASS:set RegionVar=CreateRegion() call RegionAddRect(RegionVar, gg_rct_Boom_2) call SetCSData(RegionVar, 2) call TriggerRegisterEnterRegion( BomberTrigger, RegionVar, null ) Also, after doing that I will be able to use JASS:RectContainsUnit(planeRegions[i], u) It sounds amazing how you were right Ther, the bug you described is now happening to me !! You are my only hope ! |
| 07-30-2008, 03:39 PM | #8 | ||
Quote:
You could shorten it by adding a function or a textmacro for it: JASS:globals private integer N=0 endglobals function AddRectToPath takes rect rect1, trigger trg returns nothing local region reg = CreateRegion() call RegionAddRect(reg, rect1) call SetCSData(reg, N) call TriggerRegisterEnterRegion( trg, reg, null ) set planeRegions[N]=rect1 set N=N+1 endfunction function Init takes nothing returns nothing // ... call AddRectToPath(gg_rct_Boom_1,BomberTrigger) call AddRectToPath(gg_rct_Boom_2,BomberTrigger) call AddRectToPath(gg_rct_Boom_3,BomberTrigger) call AddRectToPath(gg_rct_Boom_4,BomberTrigger) call AddRectToPath(gg_rct_Boom_5,BomberTrigger) call AddRectToPath(gg_rct_Boom_6,BomberTrigger) // ... endfunction Quote:
No, you don't need RectContainsUnit. You don't need to do the loop-check at all. Just GetCSData for the region: JASS:// WRONG!!! loop exitwhen (i == 6) if RectContainsUnit(planeRegions[i], u) then // RIGHT :) set i=GetCSData(GetTriggerRegion()) // Your unit entered planeRects[i] |
