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

[Solved] Question regarding destroy scripts

Status
Not open for further replies.
Level 7
Joined
Aug 5, 2010
Messages
147
When using scripts such as call RemoveLocation(udg_Point), call DestroyForce(udg_PlayerGroup) and set bj_wantDestroyGroup = true, would their be any issues with using the same variables on all actions that i would need to use these scripts on?
 
Last edited by a moderator:
Yes, there could be issues. Here is a simple example that demonstrates potential problems with "shared" variables:
  • Spell
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
    • Actions
      • Set TempLoc = (Target point of ability being cast)
      • Unit - Kill (Triggering unit)
      • Special Effect - Add special effect at TempLoc using model "someEffect.mdl"
      • Special Effect - Destroy (Last created effect)
      • Custom script: call RemoveLocation(udg_TempLoc)
  • Unit Dies
    • Events
      • Unit - A unit dies
    • Conditions
    • Actions
      • Set TempLoc = (Position of (Triggering unit))
      • Unit - Create 1 Footman at TempLoc facing (Default facing) degrees
      • Custom script: call RemoveLocation(udg_TempLoc)
In the two triggers above, I use "TempLoc" in both triggers. Can you spot what could go wrong with these triggers when a unit casts a spell?

----

The issue is a bit subtle; it has to do with the order in which triggers are executed:
attachment.php


Block #1 is executed first. Once it finishes "Unit - Kill unit", it jumps over to any triggers that respond to "A unit dies". It completes all of those actions, and then returns back to complete Block #3.

In Block #2, we overwrite TempLoc and then remove it. So when we jump back to Block #3, we will end up creating an effect at a destroyed location (which ends up just going to the center of the map; coordinates (0, 0) ).

So the main problem are these actions which cause other events to happen. The situation above is a bit contrived, but this can happen really easily in maps since there are so many actions that can fire events: damaging a unit, moving a unit, ordering a unit to do something, etc.

There are a lot of ways to solve this problem, but the easiest is to just use separate variables for each trigger. Sometimes you can share variables when you know they won't collide, e.g. if you have a bunch of spell triggers and none of your spells will cause another spell to go off, then you can probably share the variables between them. Just be careful about it. That is why we require spells to use unique variables when they're submitted to our database. ;)
 

Attachments

  • Order.png
    Order.png
    96 KB · Views: 111
Level 7
Joined
Aug 5, 2010
Messages
147
Would making the variables arrays stop issues from occuring?

  • Unit Dies
  • Events
  • Unit - A unit dies
  • Conditions
  • Actions
  • Set TempLoc[1] = (Position of (Triggering unit))
  • Unit - Create 1 Footman at TempLoc[1] facing (Default facing) degrees
  • Custom script: call RemoveLocation(udg_TempLoc[1])
That basiclly but the array would change for every trigger that use it
 
Level 7
Joined
Oct 19, 2015
Messages
286
That would fix it, however you are in danger of introducing really difficult-to-find bugs if you ever use the same index in two places by accident.
 
Level 7
Joined
Aug 5, 2010
Messages
147
That would fix it, however you are in danger of introducing really difficult-to-find bugs if you ever use the same index in two places by accident.

Im very meticulous so it shouldnt be that big of a problem, thanks for the help.

Edit: Just one more thing, im fairly sure this isnt an issue, but could their be any issues from having a very high array count on a single variable, say if a variable had 100 arrays.
 
Last edited:
Status
Not open for further replies.
Top