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

[Trigger] Why doesn't this detect all destructibles?

Status
Not open for further replies.
The thing that starts this is just a esc key event and sets the unit as well from another trigger.

It works on everything in the testmap except the cage destructible.

[trigger=Detect Nearest Destruct]
Events
Conditions
Actions
Destructible - Pick every destructible within 5000.00 of (Position of testunituu) and do (Actions)
Loop - Actions
Set ISD_d = (Picked destructible)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
ISD_d Equal to (Picked destructible)
Then - Actions
Set testdist = (Distance between (Position of testunituu) and (Position of ISD_d))
Set testreal = (testdist / 2.00)
Set count = 0
Destructible - Pick every destructible within testreal of (Position of testunituu) and do (Actions)
Loop - Actions
Set count = (count + 1)
Game - Display to (All players) the text: (String(count))
Set ISD_d = No destructible
Set ISD_d = (Picked destructible)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
count Equal to 1
Then - Actions
Game - Display to (All players) the text: (Name of ISD_d)
Else - Actions
Set testdist = (Distance between (Position of testunituu) and (Position of ISD_d))
Set testreal = (testdist / 2.00)
Set count = 0
Destructible - Pick every destructible within testreal of (Position of testunituu) and do (Actions)
Loop - Actions
Set count = (count + 1)
Game - Display to (All players) the text: (String(count))
Set ISD_d = No destructible
Set ISD_d = (Picked destructible)
Set ISD_d = No destructible
Set ISD_d = No destructible
Else - Actions
Set ISD_d = No destructible

[/trigger]


Uploaded the map as well just in-case the triggers don't show the issue well enough.
 

Attachments

  • GUI GetNearestWidget.w3x
    19.3 KB · Views: 42
Level 15
Joined
Oct 29, 2012
Messages
1,474
I did a test inside your map, I picked all destructibles around a dummy unit created near the cage, and then I showed their names... And yep, cage's name appeared. So your testmap isn't broken. And the cage INDEED is considered as destructible. There must something wrong in the loop. Which I don't know.
Also I assure that there is no interference between trigger. The problem is IN the trigger you posted. Maybe if I find the problem I will edit my post
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Easiest way is to loop through all destructibles in an area. You already did that and chose 5000.
Then in the loop you check if the current destructible is closer than the previous one.

This should work.

[trigger=Detect Nearest Destruct]
Events
Conditions
Actions
Set tempPoint1 = (Position of testunituu)
Set tempRealPrev = 5001.00
Set tempRealCurr = 0.00
Custom script: set tempDestPrev = null
Custom script: set tempDestCurr = null
Destructible - Pick every destructible within 5000.00 of tempPoint1 and do (Actions)
Loop - Actions
Set tempDestCurr = (Picked destructible)
Set tempPoint2 = (Position of tempDestCurr))
Set tempRealCurr = (Distance between tempPoint1 and tempPoint2)
Custom script: call RemoveLocation( udg_tempPoint2)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
tempRealCurr less than tempRealPrev
Then - Actions
Set tempRealPrev = tempRealCurr
Set tempDestPrev = tempDestCurr
Else - Actions
Custom script: // At the end here the closest destructible will be tempDestPrev
Custom script: call RemoveLocation( udg_tempPoint1)
Custom script: set udg_tempPoint1 = null
Custom script: set udg_tempPoint2 = null
Custom script: set tempDestPrev = null
Custom script: set tempDestCurr = null
[/trigger]
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
It is worth noting that in JASS a more optimized approach does exist. When computing Euclidian distances you perform a square root operation to get actual distance. When comparing for size this is completely unnecessary since basic equality relationships produce the same results before and after square root. This means that you can save a square root per iteration by only comparing the distance squared and not the actual distance.
 
One thing i always wondered regarding this: shouldn't there be a difference between code run inside a native, and code run purely in the scripting language?

Like for instance, when you groups all units in range, let's assume that the game runs this operation in C++ code. If however, you recreate the same operation in Jass, it will all be executed throught the virtual machine. Am i wrong?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Like for instance, when you groups all units in range, let's assume that the game runs this operation in C++ code. If however, you recreate the same operation in Jass, it will all be executed throught the virtual machine. Am i wrong?
Yes, which since JASS runs in a kind of interpreter (all names resolved at run time) this makes it very slow. Calling functions often take longer than the code they execute which is why there is practically no speed difference between using reals and integers despite floats physically performing slower than 32 bit integers as the call time is so long it dwarfs the underlying execution time.
 
Status
Not open for further replies.
Top