HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

rects not being moved, in a functional trigger?

03-17-2005, 04:55 AM#1
AnarkiNet
hi, im having some problems with this trigger, the units in it are being created properly however the locations which are already on my map are not being moved correctly.

Code:
function CreateUnits takes nothing returns nothing
   local location tempPoint = GetRectCenter(gg_rct_FaithSelect)
   local location whichPoint
   local integer i = 0
   local real angle
   local unit whichUnit
   local playercolor array whichColor
   local location array arrayPoint
   set whichColor[0] = PLAYER_COLOR_YELLOW
   set whichColor[1] = PLAYER_COLOR_GREEN
   set whichColor[2] = PLAYER_COLOR_ORANGE
   set whichColor[3] = PLAYER_COLOR_BLUE
   set whichColor[4] = ConvertPlayerColor(12)
   set whichColor[5] = PLAYER_COLOR_LIGHT_BLUE
   set whichColor[6] = PLAYER_COLOR_LIGHT_GRAY
   set whichColor[7] = PLAYER_COLOR_RED
   loop
 	exitwhen i > 7
 	set angle = (i+1)*(360/8) - 67.5
 	set whichPoint = PolarProjectionBJ(tempPoint, 768, angle)
 	call CreateNUnitsAtLoc( 1, 'ncp2', Player(PLAYER_NEUTRAL_PASSIVE), whichPoint, angle + 180 )
 	set whichUnit = GetLastCreatedUnit()
 	call SetUnitColor( whichUnit, whichColor[i] )
 	set arrayPoint[i] = whichPoint
 	call RemoveLocation(whichPoint)
 	set whichPoint = null
 	set i = i + 1
   endloop
   call RemoveLocation(tempPoint)
   set tempPoint = null
   call MoveRectToLoc(gg_rct_FaithLife, arrayPoint[0] )
   call MoveRectToLoc(gg_rct_FaithEarth, arrayPoint[1] )
   call MoveRectToLoc(gg_rct_FaithChaos, arrayPoint[2] )
   call MoveRectToLoc(gg_rct_FaithWater, arrayPoint[3] )
   call MoveRectToLoc(gg_rct_FaithDeath, arrayPoint[4] )
   call MoveRectToLoc(gg_rct_FaithAir, arrayPoint[5] )
   call MoveRectToLoc(gg_rct_FaithOrder, arrayPoint[6] )
   call MoveRectToLoc(gg_rct_FaithFire, arrayPoint[7] )
   set i = 0
   loop
 	exitwhen i > 7
 	call RemoveLocation(arrayPoint[i])
 	set arrayPoint[i] = null
 	set i = i + 1
   endloop
 endfunction
 
 //===========================================================================
 function InitTrig_CreateUnits takes nothing returns nothing
 	set gg_trg_CreateUnits = CreateTrigger(  )
 	call TriggerRegisterTimerEventSingle( gg_trg_CreateUnits, 0.00 )
 	call TriggerAddAction( gg_trg_CreateUnits, function CreateUnits )
 endfunction
also im not sure how "clean" that trigger is, anyone have any tips?
03-17-2005, 12:12 PM#2
Jackyquah
I think You shouldn't removeLocation in first loop.
set arrayPoint[i] = whichPoint (the location object is same)
when you call RemoveLocation(whichPoint) it's mean it's destroy the location object. so you don't have location object in arrayPoint[i]
03-17-2005, 03:45 PM#3
AnarkiNet
hmm i changed it a little and even stopped the local locations from being removed at all, and the rects STILL didnt move.
03-18-2005, 12:02 AM#4
curi
it looks to me like if you just remove

call RemoveLocation(whichPoint)

it will work. if it still won't you better create some debug messages, and for example print out the contents of the array right before the part where you move the rects.
03-18-2005, 02:13 AM#5
AnarkiNet
hmm i just realized something...could it be that because the trigger which has event "unit enters rect" is created while the rects are in their original position, that it doesnt recognize when the rects are moved?

i have ALL location removing calls commented out in the above trigger, still no worky.

EDIT: looks like that was the problem, the working trigger looks something like this:
Code:
 function CreateUnits takes nothing returns nothing
   local location tempPoint = GetRectCenter(gg_rct_FaithSelect)
   local location whichPoint
   local integer i = 0
   local real angle
   local unit whichUnit
   local playercolor array whichColor
   local location array arrayPoint
   set whichColor[0] = PLAYER_COLOR_YELLOW
   set whichColor[1] = PLAYER_COLOR_GREEN
   set whichColor[2] = PLAYER_COLOR_ORANGE
   set whichColor[3] = PLAYER_COLOR_BLUE
   set whichColor[4] = ConvertPlayerColor(12)
   set whichColor[5] = PLAYER_COLOR_LIGHT_BLUE
   set whichColor[6] = PLAYER_COLOR_LIGHT_GRAY
   set whichColor[7] = PLAYER_COLOR_RED
   loop
 	exitwhen i > 7
 	set angle = (i+1)*(360/8) - 90
 	set arrayPoint[i] = PolarProjectionBJ(tempPoint, 768, angle)
 	call CreateNUnitsAtLoc( 1, 'ncp2', Player(PLAYER_NEUTRAL_PASSIVE), arrayPoint[i], angle + 180 )
 	set whichUnit = GetLastCreatedUnit()
 	call SetUnitColor( whichUnit, whichColor[i] )
 	set i = i + 1
   endloop
   call BJDebugMsg(R2S(GetLocationX(arrayPoint[0])) + " " + R2S(GetLocationY(arrayPoint[0])))
   call MoveRectToLoc(gg_rct_FaithLife, arrayPoint[0] )
   call MoveRectToLoc(gg_rct_FaithEarth, arrayPoint[1] )
   call MoveRectToLoc(gg_rct_FaithChaos, arrayPoint[2] )
   call MoveRectToLoc(gg_rct_FaithWater, arrayPoint[3] )
   call MoveRectToLoc(gg_rct_FaithDeath, arrayPoint[4] )
   call MoveRectToLoc(gg_rct_FaithAir, arrayPoint[5] )
   call MoveRectToLoc(gg_rct_FaithOrder, arrayPoint[6] )
   call MoveRectToLoc(gg_rct_FaithFire, arrayPoint[7] )
   call TriggerRegisterEnterRectSimple( gg_trg_PickedFaithLife, gg_rct_FaithLife )
   call TriggerRegisterEnterRectSimple( gg_trg_PickedFaithEarth, gg_rct_FaithEarth )
   call TriggerRegisterEnterRectSimple( gg_trg_PickedFaithChaos, gg_rct_FaithChaos )
   set i = 0
   loop
 	exitwhen i > 7
 	call RemoveLocation(arrayPoint[i])
 	set arrayPoint[i] = null
 	set i = i + 1
   endloop
   call RemoveLocation(tempPoint)
   set tempPoint = null
 endfunction
 
 //===========================================================================
 function InitTrig_CreateUnits takes nothing returns nothing
 	set gg_trg_CreateUnits = CreateTrigger(  )
 	call TriggerRegisterTimerEventSingle( gg_trg_CreateUnits, 0.00 )
 	call TriggerAddAction( gg_trg_CreateUnits, function CreateUnits )
 endfunction
 
03-18-2005, 08:12 PM#6
curi
yeah events are dumb like that... one problem though: all the old rects are still going to set off the trigger! i think you may need to destroy the old triggers entirely and recreate them with only the new events. (there is destroy trigger but no destroy event. but it's not too hard, just call destroy trigger, make a new trigger, add the event like you did, and the conditions and the actions. you can copy the code for this from any init trigger function, like this one:

code looks something like:

// destroytrigger(gg_trg_whatever)
set gg_trg_CreateUnits = CreateTrigger( )
call TriggerAddAction( gg_trg_CreateUnits, function CreateUnits )
// add ur event, and possibly a condition
03-18-2005, 10:22 PM#7
Vexorian
Hey, the unit enters rect trigger, only creates a region and adds the rect to the region and then registers the event for the region, you'd have to move the region instead of the rect, so you'd have to create the region by yourself and save it in some variable , so you'll need umswe or to edit certain files, if you move the region it works.
03-18-2005, 10:40 PM#8
AnarkiNet
its working correctly at the moment, which is what i care about :)
also, this part of the trigger stuff shouldnt need to be "integrated" with anything else..its sort of a stand-alone thing.
03-18-2005, 10:57 PM#9
curi
"so you'll need umswe or to edit certain files, if you move the region it works." is the reason for editing files in order to make a global region variable?