• 🏆 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!

[General] Event "Unit enters region" doesn't work after using "Region - Move"

Status
Not open for further replies.
Level 1
Joined
May 6, 2016
Messages
1
Heya, re-registered after many many years, just got into mapping again tho' as title suggests i'm having a weird problem.

  • RedCycleFirst
    • Events
      • Unit - A unit enters Player1Walk1 <gen>
    • Conditions
      • (Owner of (Entering unit)) Not equal to Player 1 (Red)
    • Actions
      • Unit - Order (Entering unit) to Move To (Center of Player1Walk2 <gen>)
      • Unit Group - Remove (Entering unit) from SpawnedGroup[1]
      • Unit Group - Add (Entering unit) to FirstGroup[1]
This is the trigger that doesn't work. There are 4 of them for every player, none of them works.

I suspect this is why it doesn't work:
  • Region - Center FirstRun[(Integer B)] on ((Center of PlayerMap[(Integer B)]) offset by 1400.00 towards 45.00 degrees)
I read on the forums that setting it into a valurable will "reload" the regions position in the world, but it hasn't done any differense:
  • Trigger - Run MapRegions <gen> (ignoring conditions)
  • MapRegions
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Player Red --------
      • Set FirstRun[1] = Player1Walk1 <gen>
      • Set SecondRun[1] = Player1Walk2 <gen>
      • Set ThirdRun[1] = Player1Walk3 <gen>
      • Set FourthRun[1] = Player1Walk4 <gen>
      • -------- Player Blue ------ ...
A summary of the problem:
The units spawned are set to Unit - Move, to a series of regions (Player1Walk#1, #2, #3, and #4)
When entering the region, they should be Unit - Move, to the next one, however they don't.

Attempted solutions:
- I tried changing the trigger, so every 0.5 sec it would take all units in region and move them to the next region, and it worked just fine except it got super laggy.

Hoping someone got a suggestion what can fix this mess.
If anyone is interested in looking deeper into it, here is the map;
https://www.mediafire.com/?bf8ub6oo0h3ojww
(When map is loaded, write "-map jb" to see the problem)
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
valurable
it's variable :)

Your problem is that you don't understand event registering. Let's take a look at your case:

When you have this event:
  • Events
    • Unit - A unit enters Player1Walk1 <gen>
then what the game does at map initialization is that it looks where "Player1Walk1" region is and registers THAT AREA to fire the trigger. Basically, it just registers the coordinates ([x,y]) and width and height of the region AT MAP INITIALIZATION.

So even if you move the region some time later, the event will not get updated, and so it won't "fire".
I put "fire" in quotes, because the trigger still works and fires - but it fires only at the location where the region was upon map initialization.

Setting the region into variable has nothing to do with your issue and will not help you in any way.

The reason why the "... every 0.5 sec it would take all units in region and move them to the next region ..." approach works is because this has nothing to do with registered events, it's a standard (albeit costly) way to do something.

You have these options:
a) Dynamically add new events
You can add new event to a trigger while playing the map. The action for it is "Trigger - Add new event". So all you would need to do is move your region and then add a new event "unit enters region" to register the region you just moved.
This has some serious downsides. You can add an event, but you cannot remove it. In your case, the old locations would still fire your trigger (which may not be desired) and you could clog the trigger down with way too many events, eventually causing trigger crash (tho this does depend on how often you add new event).


b) Recreate the trigger
You could destroy the old trigger and recreate it to reflect the updated region location. However this requires JASS knowledge and there is no way to do that using standard GUI actions.


c) Use "point" instead of region
You could define a point and save it into variable and periodically select all units within X range of the point. It's a simple way to do stuff, however the downside is that you are periodically creating unit groups (which can be costly depending on how often you check units nearby the point).


d) Use dummy unit
Create a dummy unit and register it with the event "Unit - A unit comes within range of unit".
Now whenever any unit gets within range of your dummy unit, the event fires. Since this checks the location of the dummy unit during runtime, it solves your problem as well.
 
Level 4
Joined
Apr 28, 2016
Messages
33
Yeah, like Nichilus said, maybe you should use set variable as units entering the region, not with condition. Sorry if i mistake... > <
 
Level 7
Joined
Oct 19, 2015
Messages
286
To explain a bit further, the problem lies in the underlying JASS code, which uses two object types: rect and region. The regions that you place in the editor GUI are actually rects in JASS code, while trigger events use regions, so when you register a region-enter event in the trigger editor the generated JASS code has to create a new region and add the (current) rect to it before registering the event:
JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction
Moving the rect afterwards has no effect on the region that was created for the event. You'd need to also store the region and then, when you move the rect, remove it from the region beforehand and then add it again afterwards.
 
Level 2
Joined
Mar 8, 2022
Messages
4
Hi, thanks a lot for this thread, I'm doing my first TD and it helped me solve an issue with this "bug" :D

Here is what I did: I have a first wave that spreads blight, then the following wave is mobs that move faster on blight. To detect when the 2nd wave is on blight, I made the first wave drop a region where blight stops. Only then, I add an event to this region (as suggested by Nichilus)

cap1.PNG

MAKE SURE THAT THIS IS TRIGGERED ONLY ONCE (e.g., I only have one blight slug that is a "last_unit")

Cap2.PNG

Here is the trigger to which I added the event. Basically you just make your region based trigger as normal, but just don't give it any event, as it will be added later, after the region moves :)
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
Hi, thanks a lot for this thread, I'm doing my first TD and it helped me solve an issue with this "bug" :D

Here is what I did: I have a first wave that spreads blight, then the following wave is mobs that move faster on blight. To detect when the 2nd wave is on blight, I made the first wave drop a region where blight stops. Only then, I add an event to this region (as suggested by Nichilus)

View attachment 396315
MAKE SURE THAT THIS IS TRIGGERED ONLY ONCE (e.g., I only have one blight slug that is a "last_unit")

View attachment 396316
Here is the trigger to which I added the event. Basically you just make your region based trigger as normal, but just don't give it any event, as it will be added later, after the region moves :)
dat necropost.

for future reference: How To Post Your Trigger
 
Status
Not open for further replies.
Top