Region Bug?

DuelPlayer

Member
Reaction score
21
Hmm here is my code for..

JASS:
globals
region array Station_Turret_Rect 
endglobals


function Trig_Station_Turrets_Condition takes nothing returns boolean
    if IsUnitAliveBJ(udg_Station) == true then
    if ( ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true ) ) then
        return true
    endif
    if ( ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_SAPPER) == true ) ) then
        return true
    endif
    if ( ( GetTriggerUnit() == udg_AIMain ) ) then
        return true
    endif
    endif
    return false
endfunction


function Trig_Station_Turret_Actions takes nothing returns nothing
    local integer i = 0
    local location l
    loop
    exitwhen i == 4
    set i = i + 1
    if GetTriggeringRegion() == Station_Turret_Rect<i> and udg_Station_Turret_Using<i> == Player(PLAYER_NEUTRAL_PASSIVE) and udg_StationLanded == false then
    call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0,0,&quot;|cFF00FF00Now controlling the turret on station, to fire the turret, issue a move order and when you want to stop using it, walk off the circle .|r&quot;)
    set l = GetUnitLoc(udg_Station)
    set udg_Station_Turret_Using<i> = GetOwningPlayer(GetTriggerUnit())
    call SetUnitOwner( udg_Station_Turret<i>, GetOwningPlayer(GetTriggerUnit()), true )
    call ShowUnit(udg_Station_Turret<i>, true)
    call SelectUnitForPlayerSingle( udg_Station_Turret<i>, GetOwningPlayer(GetTriggerUnit()) )
    call PanCameraToTimedLocForPlayer( GetOwningPlayer(GetTriggerUnit()), l, 0 )
    call RemoveLocation(l)
    else
    endif
    endloop
endfunction


function Trig_Station_Turret_Actions2 takes nothing returns nothing
    local integer i = 0
    loop
    exitwhen i == 4
    set i = i + 1
    if GetTriggeringRegion() == Station_Turret_Rect<i> and udg_Station_Turret_Using<i> == GetOwningPlayer(GetTriggerUnit()) then
    call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0,0,&quot;|cFF00FF00You have stopped using the turret on staton&quot;)
    set udg_Station_Turret_Using<i> = Player(PLAYER_NEUTRAL_PASSIVE)
    call SetUnitOwner( udg_Station_Turret<i>, Player(PLAYER_NEUTRAL_PASSIVE), true )
    call ShowUnit(udg_Station_Turret<i>, false)
    else
    endif
    endloop
endfunction

//===========================================================================
function InitTrig_Station_Turret takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t2 = CreateTrigger()
    local integer i = 0
    set Station_Turret_Rect[1] = CreateRegion()
    set Station_Turret_Rect[2] = CreateRegion()
    set Station_Turret_Rect[3] = CreateRegion()
    set Station_Turret_Rect[4] = CreateRegion()
    call RegionAddRect(Station_Turret_Rect[1],gg_rct_Station_Turret_1)
    call RegionAddRect(Station_Turret_Rect[2],gg_rct_Station_Turret_2)
    call RegionAddRect(Station_Turret_Rect[3],gg_rct_Station_Turret_3)
    call RegionAddRect(Station_Turret_Rect[4],gg_rct_Station_Turret_4)    
    loop
    exitwhen i == 4
    set i = i + 1
    call TriggerRegisterEnterRegion(t, Station_Turret_Rect<i>, null)
    call TriggerRegisterLeaveRegion(t2, Station_Turret_Rect<i>, null)
    endloop
    call TriggerAddCondition(t, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddCondition(t2, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddAction(t, function Trig_Station_Turret_Actions )
    call TriggerAddAction(t2, function Trig_Station_Turret_Actions2 )
endfunction

</i></i></i></i></i></i></i></i></i></i></i></i></i>


yeah and the problem is that there is no message shown when i goes into the region
Please highlight any mistakes I made

Thanks in advance
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Are the conditions passed to execute the actions? To check, just add a message outside of the loop in both "actions" functions.

If that message shows, then you know that it is a problem with the line:
[ljass]if GetTriggeringRegion() == Station....[/ljass]
If it does not show, then that means that there is a problem with your conditions.

Also, you can use the [noparse]
JASS:
[/noparse] tags to highlight the code for it to be easier to read. =)
 

DuelPlayer

Member
Reaction score
21
Are the conditions passed to execute the actions? To check, just add a message outside of the loop in both "actions" functions.

If that message shows, then you know that it is a problem with the line:
[ljass]if GetTriggeringRegion() == Station....[/ljass]
If it does not show, then that means that there is a problem with your conditions.

Also, you can use the [noparse]
JASS:
[/noparse] tags to highlight the code for it to be easier to read. =)
JASS:
I tried. But it is still not working <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" />
And thanks for the reminder for [noparse]<div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="symbol">[</span><span class="symbol">/</span><span>noparse</span><span class="symbol">]</span> <span>tags</span></code></pre></div></div>
 

phyrex1an

Staff Member and irregular helper
Reaction score
446
You never set the nor increment the [ljass]local integer i[/ljass] in [ljass]Trig_Station_Turret_Actions[/ljass] or [ljass]Trig_Station_Turret_Actions2[/ljass]. Check how you did in [ljass]InitTrig_Station_Turret[/ljass]. Also, do you initialize [ljass]udg_Station_Turret_Using[1..4][/ljass] with [ljass]Player(PLAYER_NEUTRAL_PASSIVE)[/ljass]?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
also in your loops, i never gets higher so how does it ever hit 4?
it starts with no value so you cant use it in code where it uses i other than conditions or it will crash the thread (i = ???, so set i = i + 1 = ??? + 1, the computer gives up and shuts that trigger down, you have to set it to 0 for it to be initialized correctly) so you are using it to refer to an array, so the computer goes [ljass]Station_Turret_Rect[???] = ???[/ljass] it doesnt actually reference everything and stops the thread

also, at the end of your loop, add the line:
[ljass]set i = i + 1[/ljass] so i gets higher, then when it becomes 4 it will exit the loop, till then it will be endlessely looping and cause the computer to hit its op limit and crash wc3

PS.

please indent right, IE:

JASS:
function something takes something returns nothing
    loop
        exitwhen Something
        do stuff
        if this then
            do more stuff
        elseif this then
            do other more stuff
        else
            do other more stuff
        endif
    endloop
endfunction


every layer of encapsulation is another indent (makes it a LOT easier to read)

PPS:

instead of [ljass]call TriggerAddAction(trigger, function Actions)[/ljass] do [ljass]call TriggerAddCondition(trigger, Filter(function Actions))[/ljass] because actions leak, but you can use your actions as a condition, make them return boolean, and false at the end, and they will work the same way, just like an action but with no leak

PPPS:

you leak a lot of things
locals must be nulled if they are not a real number, integer, or struct variable
so just do:

[ljass]set localvariable = null[/ljass]

to clear those leaks
the exception is groups, which are cleared via: [ljass]call DestroyGroup(variable)[/ljass]
 

DuelPlayer

Member
Reaction score
21
also in your loops, i never gets higher so how does it ever hit 4?
it starts with no value so you cant use it in code where it uses i other than conditions or it will crash the thread (i = ???, so set i = i + 1 = ??? + 1, the computer gives up and shuts that trigger down, you have to set it to 0 for it to be initialized correctly) so you are using it to refer to an array, so the computer goes [ljass]Station_Turret_Rect[???] = ???[/ljass] it doesnt actually reference everything and stops the thread

also, at the end of your loop, add the line:
[ljass]set i = i + 1[/ljass] so i gets higher, then when it becomes 4 it will exit the loop, till then it will be endlessely looping and cause the computer to hit its op limit and crash wc3

PS.

please indent right, IE:

JASS:
function something takes something returns nothing
    loop
        exitwhen Something
        do stuff
        if this then
            do more stuff
        elseif this then
            do other more stuff
        else
            do other more stuff
        endif
    endloop
endfunction


every layer of encapsulation is another indent (makes it a LOT easier to read)

PPS:

instead of [ljass]call TriggerAddAction(trigger, function Actions)[/ljass] do [ljass]call TriggerAddCondition(trigger, Filter(function Actions))[/ljass] because actions leak, but you can use your actions as a condition, make them return boolean, and false at the end, and they will work the same way, just like an action but with no leak

PPPS:

you leak a lot of things
locals must be nulled if they are not a real number, integer, or struct variable
so just do:

[ljass]set localvariable = null[/ljass]

to clear those leaks
the exception is groups, which are cleared via: [ljass]call DestroyGroup(variable)[/ljass]

Thanks for your help...
I did realised I forgot to increase, silly me
but even after I changed, it still don't work....
I got a feeling that it is not related to those loop instead because even without the increment, the warcraft still did not crashed
PS: I only do indentation for very complicated script
If i null the trigger, wouldn't they stop working.....

You never set the nor increment the [ljass]local integer i[/ljass] in [ljass]Trig_Station_Turret_Actions[/ljass] or [ljass]Trig_Station_Turret_Actions2[/ljass]. Check how you did in [ljass]InitTrig_Station_Turret[/ljass]. Also, do you initialize [ljass]udg_Station_Turret_Using[1..4][/ljass] with [ljass]Player(PLAYER_NEUTRAL_PASSIVE)[/ljass]?

Thanks for your help...
Yeah I did not notice it... thanks for reminder
And I did initialize it in another trigger
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
when u null the trigger it sets the variable to null, but does nothing to the actual trigger except erase it's handle and recycle it, basically because you saved the reference to that trigger it is keeping that reference until it is nulled, but if you null the variable it erases that reference and the trigger is no longer referenced at all so you can erase the "ID" for the trigger or handle for it...
its kinda complex, but setting variables to null does nothing to what is inside the variable except prevent leaks

JASS:
function InitTrig_Station_Turret takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t2 = CreateTrigger()
    local integer i = 0
    set Station_Turret_Rect[1] = CreateRegion()
    set Station_Turret_Rect[2] = CreateRegion()
    set Station_Turret_Rect[3] = CreateRegion()
    set Station_Turret_Rect[4] = CreateRegion()
    call RegionAddRect(Station_Turret_Rect[1],gg_rct_Station_Turret_1)
    call RegionAddRect(Station_Turret_Rect[2],gg_rct_Station_Turret_2)
    call RegionAddRect(Station_Turret_Rect[3],gg_rct_Station_Turret_3)
    call RegionAddRect(Station_Turret_Rect[4],gg_rct_Station_Turret_4)    
    loop
    exitwhen i == 4
    set i = i + 1
    call TriggerRegisterEnterRegion(t, Station_Turret_Rect<i>, null)
    call TriggerRegisterLeaveRegion(t2, Station_Turret_Rect<i>, null)
    endloop
    call TriggerAddCondition(t, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddCondition(t2, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddAction(t, function Trig_Station_Turret_Actions )
    call TriggerAddAction(t2, function Trig_Station_Turret_Actions2 )
endfunction

//================================================================
//---------------------&gt;

function InitTrig_Station_Turret takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger t2 = CreateTrigger()
    local integer i = 0
    set Station_Turret_Rect[1] = CreateRegion()
    set Station_Turret_Rect[2] = CreateRegion()
    set Station_Turret_Rect[3] = CreateRegion()
    set Station_Turret_Rect[4] = CreateRegion()
    call RegionAddRect(Station_Turret_Rect[1], Station_Turret_Rect[1])
    call RegionAddRect(Station_Turret_Rect[2], Station_Turret_Rect[2])
    call RegionAddRect(Station_Turret_Rect[3], Station_Turret_Rect[3])
    call RegionAddRect(Station_Turret_Rect[4], Station_Turret_Rect[4])    //its here, i believe these variables were referenced incorrectly in your code
    loop
    exitwhen i == 4
    set i = i + 1
    call TriggerRegisterEnterRegion(t, Station_Turret_Rect<i>, null)
    call TriggerRegisterLeaveRegion(t2, Station_Turret_Rect<i>, null)
    endloop
    call TriggerAddCondition(t, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddCondition(t2, Condition(function Trig_Station_Turrets_Condition))
    call TriggerAddAction(t, function Trig_Station_Turret_Actions )
    call TriggerAddAction(t2, function Trig_Station_Turret_Actions2 )
endfunction</i></i></i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top