• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] triggerregister EnterRectSimple vs EnterRegion

Level 3
Joined
Feb 11, 2024
Messages
22
I bumped into a very strange (sry if it's already known) case regarding TriggerRegisterEnterRectSimple and TriggerRegisterEnterRegion.
AFAIK EnterRectSimple is simply making the rect to region in JASS and calling EnterRegion for that new region. (TriggerRegister omitted)

But if I use EnterRegion like below, the trigger is not working AND all triggers below it are not working!
JassHelper says there's no error when I save the map.

If I use EnterRectSimple( gg_trg_SpellA, GetPlayableMapRect() ), the trigger works well AND all triggers below it work well.

Why is this happening?

JASS:
function SpellA_Conditions takes nothing returns boolean

    if GetUnitTypeId(GetTriggerUnit()) == 'h001' then
        // actions
    endif

    return false
endfunction

function InitTrig_SpellA takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRegion(t,IPA,null)
    call TriggerAddCondition(t, Condition( function SpellA_Conditions ) )
    set t = null
endfunction

Note that the spell which is creating the 'h001' is based on Tinker's Summon Factory (ANs1).

Also note that IPA is declared at map initialization (elapsed 0 seconds), and my other two triggers which are also using it works well.
(Well for these two triggers, the spells are Locust Swarm based, maybe this matters?)

JASS:
set IPA=CreateRegion()
call RegionAddRect(IPA,bj_mapInitialPlayableArea)
 
Level 3
Joined
Feb 11, 2024
Messages
22
I think I came to an answer myself, because IPA is declared at 0 second but InitTrig is fired even before 0 second.

But then why does it makes all triggers below it to not work?
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
But then why does it makes all triggers below it to not work?
By attempting to reference/use an uninitialized variable you crash the thread the code was operating from. In this instance that’s the main map init thread since that’s where InitTrigs are run from, so every InitTrig after this one is never run.

In general you want to be using libraries and scopes with requirements for things like this. If one requires another then the required one will always be above the requiring one in code and will have executed first. You could then be sure that IPA would be initialized. Using normal map init thread and InitTrigs don’t really play well with scope/library requirements but since such structures also have an initializer keyword you can give them their own inits.
 
Level 3
Joined
Feb 11, 2024
Messages
22
@Pyrogasm, thanks for the reply, understood why triggers below that never worked. And also what is the role of scopes' initializers too!
 
Top