HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

The event "Unit Leaves Region" is bugged?

11-10-2007, 08:08 PM#1
Salbrismind
I finished my code and tried it, and it didn't work. After putting messages around the code I found out that the trigger just isn't being started by the event. I origrinally had this:

Collapse JASS:
function InitTrig_Endless_Arena_x takes nothing returns nothing
    set gg_trg_Endless_Arena_x = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_Endless_Arena_x, Rect(-6000.00, -6100.00, 6000.00, 6100.00) )
    call TriggerAddAction( gg_trg_Endless_Arena_x, function Trig_Endless_Arena_x_Actions )
    set gg_trg_Endless_Arena_x = null
endfunction

But that didn't work. So i changed it to use a region instead of a rectangle:

Collapse JASS:
function InitTrig_Endless_Arena_x takes nothing returns nothing
    local region Map_Bounds = CreateRegion()
    call RegionAddRect(Map_Bounds, Rect(-6000,-6100,6000,6100))
    set gg_trg_Endless_Arena_x = CreateTrigger(  )
    call TriggerRegisterLeaveRegion ( gg_trg_Endless_Arena_x, Map_Bounds, null)
    call TriggerAddAction( gg_trg_Endless_Arena_x, function Trig_Endless_Arena_x_Actions )
    call BJDebugMsg ("This trig works?")
endfunction

But it still didn't work. Can anyone tell me how to fix this? +rep

Here's the whole code:

Collapse JASS:
function Endless_Arena_x_Actions takes unit u, location pos returns nothing
local integer count = 0
local integer tempI
local unit Otheru
local location Otherpos = GetUnitLoc(Otheru)
local real tempx
local real tempxo
local real tempy
local real tempyo
call BJDebugMsg ("THis works?")
loop
    set count = count + 1
    if udg_ship[count] == u then
    set tempI = (R2I(count/2-0.6))     
    set Otheru = udg_ship[tempI+(3-(count-tempI))]
    exitwhen udg_ship[count] == u 
    endif
endloop
 
if udg_curangle[count] < 270 and udg_curangle[count] > 90  then
    if GetUnitFacing(u) > 90 and GetUnitFacing(u) < 270  then
    set tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos)           
    set tempy = GetLocationY (pos)
    set tempxo = -1 * GetLocationX(pos)
    set tempyo = GetLocationY (pos)
    elseif GetUnitFacing(u) > 270 and GetUnitFacing(u) < 90  then
    set tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos) + (RSignBJ(GetLocationX(pos))*1500)          
    set tempy = GetLocationY (pos)
    set tempxo = -1 * GetLocationX(pos) + (RSignBJ(GetLocationX(pos))*1500)
    set tempyo = GetLocationY (pos)
    endif
elseif udg_curangle[count] > 270 and udg_curangle[count] < 90  then
    if GetUnitFacing(u) > 270 and GetUnitFacing(u) < 90  then
    set tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos)           
    set tempy = GetLocationY (pos)
    set tempxo = -1 * GetLocationX(pos)
    set tempyo = GetLocationY (pos)
    elseif GetUnitFacing(u) > 90 and GetUnitFacing(u) < 270 then
    set tempx = (-1*GetLocationX(pos)) + GetLocationX(pos) - GetLocationX(Otherpos) + (RSignBJ(GetLocationX(pos))*1500)          
    set tempy = GetLocationY (pos)
    set tempxo = -1 * GetLocationX(pos) + (RSignBJ(GetLocationX(pos))*1500)
    set tempyo = GetLocationY (pos)     
    endif
endif
call SetUnitPosition (Otheru, tempxo, tempyo)
call SetUnitPosition (u, tempx, tempy)
set Otherpos = null
set Otheru = null  
endfunction

function Trig_Endless_Arena_x_Actions takes nothing returns nothing
    call Endless_Arena_x_Actions ( GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()) )
    call BJDebugMsg ("how bout?")
endfunction

//===========================================================================
function InitTrig_Endless_Arena_x takes nothing returns nothing
    local region Map_Bounds = CreateRegion()
    call RegionAddRect(Map_Bounds, Rect(-6000,-6100,6000,6100))
    set gg_trg_Endless_Arena_x = CreateTrigger(  )
    call TriggerRegisterLeaveRegion ( gg_trg_Endless_Arena_x, Map_Bounds, null)
    call TriggerAddAction( gg_trg_Endless_Arena_x, function Trig_Endless_Arena_x_Actions )
    call BJDebugMsg ("This trig works?")
endfunction
11-10-2007, 11:38 PM#2
cohadar
Collapse JASS:
function InitTrig_Endless_Arena_x takes nothing returns nothing
    set gg_trg_Endless_Arena_x = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_Endless_Arena_x, Rect(-6000.00, -6100.00, 6000.00, 6100.00) )
    call TriggerAddAction( gg_trg_Endless_Arena_x, function Trig_Endless_Arena_x_Actions )
    set gg_trg_Endless_Arena_x = null // ERROR
endfunction

Do NOT null global triggers.
Do NOT null ANYTHING unless YOU declared it as LOCAL before that

Collapse JASS:
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterLeaveRectSimple( trig, Rect(-6000.00, -6100.00, 6000.00, 6100.00) )
    call TriggerAddAction( trig, function Trig_Endless_Arena_x_Actions )
    set trig = null // now it is OK because trig is local
endfunction

EDIT:
try this
11-11-2007, 12:53 AM#3
Pyrogasm
Yeah... except for the fact that nulling a trigger does not mean it doesn't still have events/conditions/actions. The reference to the trigger just no longer exists whilst the trigger still does, so that is evidently not his problem.

This is the real error:
Collapse JASS:
local unit Otheru
local location Otherpos = GetUnitLoc(Otheru)
Otheru is uninitialized when you're trying to get the location of it and, thus, the trigger is crashing. Change that first line to local unit Otheru = null and it won't crash... but the variable still won't reference a unit.

Additionally, this will cause compile errors, as the variable "u" doesn't exist:
Collapse JASS:
exitwhen udg_ship[count] == u

Last, you're referencing the variable pos a lot in the second half of the trigger. That variable also doesn't exist and will cause compile errors.
11-11-2007, 02:36 AM#4
cohadar
I wrongly assumed he was trying to call that trigger from another one and that is because it failed, so I did not bother to read on..

Well maybe it is not his main error but it is still an error,
and my statement still stands:
Do NOT null global triggers.
11-11-2007, 03:26 AM#5
Salbrismind
Ya, didn't realize that was a global (basically my second Jass and the tutorial told me to null trigs like that) so I'll make sure I remember that.

And thanks for pointing that out Pyro, I see now what I did wrong, before this I had to move my local decs from inside the ifs at the bottom so before "Otheru" would have been set properly but now it isn't.

Oh, and u and pos are variables they are the parameters of the trigger it self.

Again, thanks +rep!
11-11-2007, 03:31 AM#6
Pyrogasm
Shit, son. You can't do that. You cannot pass arguments to a trigger's actionfunc.

It WILL crash.
11-11-2007, 08:25 AM#7
PandaMine
nulling global variables doesnt do anything bad, you just have to make sure you wont use it in the future, or if you do to make sure it is nulled
11-11-2007, 09:48 AM#8
cohadar
Quote:
Originally Posted by PandaMine
nulling global variables doesnt do anything bad
FALSE

Quote:
Originally Posted by PandaMine
or if you do to make sure it is nulled
FALSE


Nulling WE generated globals IS a bad thing, ALWAYS.
And you DON'T have to null globals not even "after" you use them.
11-11-2007, 10:41 AM#9
Toadcop
no no 100% this event may be bugged ! (i have (but found a work around way) this issue in TcX) yes it may happen what LeaveReg will not trigger. =\ idk why maybe it not allow to move more than once units from 1 to the other region (which does have this event).
what i mean yes i may happen what leave event may fail ! (it's proofed) it's kind a random bug.
11-11-2007, 12:10 PM#10
Vexorian
The problem here is far from being related to nulling a global, but using a global there... unless you want to mess with the trigger later it just doesn't make any sense to use a global there, unless you blindly follow world editor's silly suggestions as to how to use custom text.

Quote:
Nulling WE generated globals IS a bad thing, ALWAYS.
Total non-sense. I can only think of it as a problem if you actually try to use the trigger variable elsewhere or if you use WE's lame "run on map init"

The real sentence would be "using WE generated globals is lame"
11-11-2007, 12:18 PM#11
cohadar
When things can create problems they are dangerous,
when things are dangerous they are bad.

It does not matter if chance of a problem is small,
as long as there is a chance a problem is still a problem.

Quote:
Originally Posted by Vexorian
The real sentence would be "using WE generated globals is lame"

true. true.

@Salbrismind
If you want to learn how to avoid using WE generated stuff read this.
11-11-2007, 04:15 PM#12
Salbrismind
Quote:
Originally Posted by Pyrogasm
Shit, son. You can't do that. You cannot pass arguments to a trigger's actionfunc.

It WILL crash.

I can't use the parameters? If thats what you mean, your wrong, I finished the code and it works.



And no worry guys I don't ever plan to use WE defaulted code for trigs. Just I got lazy...
11-11-2007, 07:23 PM#13
Pyrogasm
Oh; I didn't see you had two separate functions with only two slightly different names. In that case, your code is OK.