• 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.

Most efficient way to check if a unit is in range?

Status
Not open for further replies.
Level 8
Joined
Oct 3, 2008
Messages
189
Hi everyone,

so I'm making a spell that drops an orb when it hits the target. The caster can walk near the orb to automatically consume for a beneficial effect.

Now I was wondering, how do you best handle this? Right now I'm using the "specific unit comes within range of unit" event, and adding a new event to it whenever a new orb gets created. I'm a bit concerned that there might be a limited amount of events that can be added to a trigger or another problem?

The alternative is using a periodic event to check whether the caster is within range of the orb, but there my worry is that this might be a lot more resource intensive?

Any thoughts?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Now I was wondering, how do you best handle this? Right now I'm using the "specific unit comes within range of unit" event, and adding a new event to it whenever a new orb gets created. I'm a bit concerned that there might be a limited amount of events that can be added to a trigger or another problem?
Events can leak if used like that. However one can solve it by creating a unique trigger per orb, or periodically destroying and recreating the trigger. Destroying a trigger also destroys all attached events.
 
Level 15
Joined
Jul 12, 2018
Messages
560
i have something like that in my map. The "orb" in my case is a unit with no movement. The unit has a spell based on heal, set to autocast. there's a trigger that destroys the unit after casting the heal. the unit also has an expiration timer that's added at the time it gets created.
 
Level 8
Joined
Oct 3, 2008
Messages
189
Events can leak if used like that. However one can solve it by creating a unique trigger per orb, or periodically destroying and recreating the trigger. Destroying a trigger also destroys all attached events.

Having a bunch of triggers around for units that no longer exist would occupy no memory or would the intent be to still destroy the trigger after the unit expires / is picked up?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Having a bunch of triggers around for units that no longer exist would occupy no memory or would the intent be to still destroy the trigger after the unit expires / is picked up?
Having a bunch of triggers around for units that no longer exist does occupy memory and handle ID numbers. A typical memory/resource leak.

One could create a trigger per unit and then destroy that trigger when the unit gets removed (you can detect this using the shield ability of the footman, it issues an unshield order when a unit is being removed). Destroying triggers is safe as long as the trigger is not scheduled for execution when it is destroyed.

This requires using JASS directly because of GUI lacking functionality.
 
Level 4
Joined
Jan 16, 2013
Messages
16
Out of curiosity, what's wrong with "unit enters region" and "check if a unit has a buff"?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Out of curiosity, what's wrong with "unit enters region" and "check if a unit has a buff"?
Quite complex to program and basically results in similar code to a unit enters X of unit approach.

The regions need to be created, events for them created, after the orb is removed both need to be destroyed meaning dynamic trigger destruction/recreation.
 
Status
Not open for further replies.
Top