• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Region not Triggering

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I have this issue which is quite silly. I have a region and when a player-owned hero enters it, the player receives 200 gold and the trigger is the deactivated. The problem is that it doesn't register when the hero enters the region. Here is my trigger and script:

  • Hidden Gold
    • Events
      • Unit - A unit enters HiddenGold <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Owner of (Triggering unit)) Not equal to Player 12 (Brown)
    • Actions
      • Custom script: call Hidden_Gold(GetTriggerUnit())
JASS:
function Hidden_Gold takes unit u returns nothing
    call DisplayTextToForce(GetPlayersAll(), GetPlayerName(GetOwningPlayer(u)) + "has found the hidden gold!")
    call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + 200)
    call DisableTrigger(gg_trg_Hidden_Gold)
    set u = null
endfunction
Notes:
- My map is an arena where you choose a hero and kill creeps.
- I move the region to a random point for each new level.
- I reactivate the trigger for each new level (you can only find the hidden gold once per level).

Can someone please show me the error? I know that I should do everything in JASS, but I am still learning it and I would prefer to do it with both triggers and JASS.

Thanks for reading!
 
That's because there are 2 kinds of regions :
- The GUI regions are what you create in the Terrain editor and you use them in GUI but their name is rect in jass,
- The jass regions are mostly invisible in GUI and used only to register events.

This is the registration of the GUI event "A unit enters Region"
JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction

As you can see, the registration creates a region and don't use directely the rect : if you edit the rect, the region however doesn't change.

So you have to use jass and edit jass regions instead of rects. The JNGP (UMSWE more precisely) enables the type "jass regions" but you can also use custom script (you will need the JNGP to declare a global region anyway).

JASS:
globals
    region myRegion
endglobals

function LaunchAtMapInitialization takes nothing returns nothing
    set myRegion = CreateRegion()
    call RegionAddRect(myRegion, gg_rct_HiddenGold)
    call TriggerRegisterEnterRegion(gg_trg_Hidden_Gold, myRegion, null)
endfunction

function MoveRectAndRegion takes real newCenterX, real newCenterY returns nothing
    call RegionClearRect(myRegion, gg_rct_HiddenGold)
    call MoveRectTo(gg_rct_HiddenGold, newCenterX, newCenterY)
    call RegionAddRect(myRegion, gg_rct_HiddenGold)
endfunction

I don't know the UMSWE's actions name but I guess it can all be done with them.
 
Level 26
Joined
Mar 19, 2008
Messages
3,140
I would even combine both GUI and jass script to make for simplicity:
JASS:
function HidenGoldConditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local string s
    if IsUnitType(u, UNIT_TYPE_HERO) and p!= Player(11) then
        set s = GetPlayerName(p) + "has found the hidden gold!"
        if IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS) then
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, s)
        endif
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + 200)
        call DisableTrigger(GetTriggeringTrigger())
    endif
    set u = null
    set p = null
    return false
endfunction

function InitTrig_Hidden_Gold takes nothing returns nothing
    local trigger t = CreateTrigger()
    local region r = CreateRegion()
    call RegionAddRect(r, gg_rct_HiddenGold)
    call TriggerRegisterEnterRegion(t, r, null)
    call TriggerAddCondition(t, Condition(function HidenGoldConditions))
    set t = null
    set r = null
endfunction
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Thanks guys, but even when I do this, it still doesn't detect the entering unit:

  • Hidden Gold
    • Events
      • Unit - A unit enters HiddenGold <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Owner of (Triggering unit)) Not equal to Player 12 (Brown)
    • Actions
      • Game - Display to (All players) the text: Entered!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,223
Remove the conditions to test if it is even registering units entering the region. If it does then you know its a fault with the condition. If it does not then you might be hitting the map initialization op limit or the rect the region is made from is broken.

A common cause for hitting the map initialization op limit is people foolishly using GUI arrays and getting it to initialize a high array index. As it itterates through each index it initializes you can easilly hit the op limit if you set a few array sizes to 8000 odd. Be aware that the arrays JASS uses are dynamic thus they have no real size (next to the hard coded limit of 2^13 indicies). Also making thousands of event setup calls on the initializtion thread can cause this.

If the conditions are the cause of the problem, attempt to find which condition.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hmmm, thanks for your reply. I don't have any huge array sizes (the biggest is 30, but most are 4). I do set a lot of variables at map initialization - could this have something to do with it? What can I do to fix this?

EDIT: I tried setting all the variables after 0.01 seconds but this makes no difference.
EDIT 2: Some of my triggers/scripts don't work at all...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,223
As you are aware, trigger script threads have an op limit placed on them. An op limit limits the number of opperations the thread can carry out before automatically terminating.

An example of the op limit in use is to simply place...
JASS:
loop
endloop
in a function. When the interpreter gets to that stage the game will not crash and instead it just stops executing (as it loops until the op limit is reached and then the thread crashes).

The script initialization thread that the game client creates when the map is loading also has such an op limit. If you run too much script on the map initialization thread it can cause it to crash and thus script will be skipped. This is why you are advised to outsource expensive (op wise) initialization procedures to separate threads.

Also be aware that there are other ways to crash a thread. Example being as simple as division by 0 or referencing an uninitialized variable will cause the executing thread to crash.
 
Creating a load of units during the beginning of the game also causes very strange errors. If you have any JASS scripts in the map a function by the name of InitTrig_TriggerName also cannot call Waits as those will also cause the game to crash.

Stuff you do in a Map Initialization trigger will generally not endanger the op limit as those run in their own threads and not the main thread.
 
Well I would try changing it to a different region, seeing if the problem persists, also check your map initialization triggers and make sure that nothing is causing an infinite loop, also check again your array variables there's no reason to initialize an array to size 30, at the most you'd use size 13 (because GUI users like to ignore the 0 index for players).

If it still is corrupt then post the map.
 
Status
Not open for further replies.
Top