• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Code glitch dealing with rects/regions/events

Status
Not open for further replies.

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
This function has a serious problem. If I put the code in another fucntion, that function doesn't execute. If I have it be called from a function, neither function will execute. This is what I'm working with:
JASS:
globals
region array regio
region array tooltip
rect zero
endglobals

JASS:
function createregions1 takes nothing returns nothing
local rect zero
local integer a = 0
set regio[0]=CreateRegion()
set zero = Rect(- 7968.0, - 6816.0, - 7520.0, - 6752.0)
call RegionAddRect(regio[0], zero)
call TriggerRegisterEnterRegion(gg_trg_G9, regio[0], null)
set regio[1]=CreateRegion()
set zero=Rect(- 4384.0, - 4992.0, - 3936.0, - 4928.0)
call RegionAddRect(regio[1], zero)
call TriggerRegisterEnterRegion( gg_trg_S1Rez, regio[1], null )
loop
exitwhen a > 7
set tooltip[a]=CreateRegion()
call TriggerRegisterLeaveRegion(gg_trg_TTNo, tooltip[a], null)
set a = a + 1
endloop
set zero=Rect(- 4480.0, - 6592.0, - 4416.0, - 6208.0)
call RegionAddRect(boss1trigger, zero)
call TriggerRegisterEnterRegion( gg_trg_S1Boss, boss1trigger, null )
set zero=Rect(- 7616.0, - 7872.0, - 7552.0, - 7776.0)
call RegionAddRect(tooltip[0], zero)
call TriggerRegisterEnterRegion(gg_trg_TT1, tooltip[0], null)
set zero=Rect(- 7936.0, - 8256.0, - 7872.0, - 8160.0)
call RegionAddRect(tooltip[1], zero)
call TriggerRegisterEnterRegion(gg_trg_TT2, tooltip[1], null)
set zero=Rect(- 7936.0, - 7488.0, - 7872.0, - 7392.0)
call RegionAddRect(tooltip[2], zero)
call TriggerRegisterEnterRegion(gg_trg_TT3, tooltip[2], null)
set zero=Rect(- 7616.0, - 7488.0, - 7552.0, - 7392.0)
call RegionAddRect(tooltip[3], zero)
call TriggerRegisterEnterRegion(gg_trg_TT4, tooltip[3], null)
set zero=Rect(- 7616.0, - 8256.0, - 7552.0, - 8160.0)
call RegionAddRect(tooltip[4], zero)
call TriggerRegisterEnterRegion(gg_trg_TT5, tooltip[4], null)
set zero=Rect(- 8000.0, - 8576.0, - 7936.0, - 8480.0)
call RegionAddRect(tooltip[5], zero)
call TriggerRegisterEnterRegion(gg_trg_TT6, tooltip[5], null)
set zero=Rect(- 7552.0, - 8576.0, - 7488.0, - 8480.0)
call RegionAddRect(tooltip[6], zero)
call TriggerRegisterEnterRegion(gg_trg_TT7, tooltip[6], null)
set zero=Rect(- 7936.0, - 7872.0, - 7872.0, - 7776.0)
call RegionAddRect(tooltip[7], zero)
call TriggerRegisterEnterRegion(gg_trg_TT8, tooltip[7], null)
set zero=null
endfunction
 
Level 7
Joined
Oct 14, 2008
Messages
340
For starters, you should indent your codes, the way you have it pasted here makes it really hard to read.

Now, have you tried moving that loop to AFTER the rects are added to the region?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
So, I was reading over my old posts to see how my coding has improved, and...

The reason why this was causing the game to crash was because I was declaring rect zero as a global AND as a local.

That was because when I first started learning JASS I thought that locals had to be declared as globals, first o_O

If I were still programming this, it would look like:

JASS:
scope CreateRegions initializer init
globals
    region array regio
    region array tooltip
endglobals
private function Setup takes rect r, trigger t, region e returns nothing
    set e = CreateRegion()
    call RegionAddRect( e , r )
    call TriggerRegisterEnterRegion( t , e , null )
    call RemoveRect( r )
endfunction
private function init takes nothing returns nothing
    local rect r
 
    // do this for each one:
    set r = somerect
    call Setup(r,trig,region)
    // ^^^
 
    set r = null
endfunction
endscope
 
Last edited:
Status
Not open for further replies.
Top