• 🏆 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] Destroying a Specific Index "[ ]" of a Variable with Custom Script?

Status
Not open for further replies.
Level 4
Joined
Dec 24, 2016
Messages
42
Hi Everyone,

At the moment, I am making a Hero RPG with customizable spells. However, I ran into a problem with memory leaks. I am using a UnitGroup[ ] Variable so that there is the same number of indexes as there are total players (9 in this case). I am doing this because I need to account for events to happen based on the actions of each individual player (in this case: knocking back a unit each .01 second based on the buff duration of "War Stomp"). I am using an array for each player so that on the rare occasion that multiple players use the same spell at the same time, the units affected would react in its respective manner.

I have read online that leaving variables filled with unused assets will drag down the game. I am wondering how to destroy specific indexes in a variable (using GUI), without having to clear the entire variable as a whole. If I clear the variable as a whole, the effects are done with one player's cast, stopping the effects of the spell for another player who might be casting the spell at the same time.

I do not have experience coding vJass and I prefer to remain using GUI.

EXAMPLE:

Set UnitGroup Spell_Targets[1] = BlahBlahBlah <--- I just want to clear Spell_Targets[1]
Custom Script: DestroyGroup(udg_Spell_Targets) <--- ??? What to do here?

I know no clear method to tell whether single Memory Leaks will slow down the game; for all I know, it could be "DestroyGroup(udg_Spell_Targets[1])," but I feel knowing this info would allow me to smooth out the game in the long run. I appreciate all the help I could get.


P.S. Is it required to clear Unit variables (Spell_Target = (Target Unit of Ability Cast))? The general consensus for clearing units seems to be killing them off.
 
Level 4
Joined
Dec 24, 2016
Messages
42
Ah, thank you. However, is there a mean to set that index to an "Integer A" for a loop? So far, I have tried:

(udg_Spell_Targets[A])
(udg_Spell_Targets[Integer A])
(udg_Spell_Targets[int A])

I am assuming all of the above are way off from the actual solution. Also, thank you for forwarding me to that thread; it's very helpful.
 
Level 14
Joined
Nov 30, 2013
Messages
926
  • Actions
    • -------- Use "GetForLoopIndexA()" for Integer A Loop --------
    • -------- Use "GetForLoopIndexB()" for Integer B Loop --------
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • Custom script: call DestroyGroup(udg_Spell_Targets[GetForLoopIndexA()])
 
Level 10
Joined
Sep 16, 2016
Messages
269
Since GetForLoopIndexA is a function, it's better to use
  • call DestroyGroup( udg_Spell_Targets[ bj_forLoopAIndex ] )
It is recommended that you used "For each integer variable from 1 to 10" rather than For each integer A/B. that way you can call the variable easily and the loop doesn't get interrupted.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
@AquaFire If you want to see what something looks like in JASS (to learn how you'd have to write it in a custom script) you can right click a trigger and choose "convert to custom text", which will make it all JASS. You can't undo this so make sure you do it to a copy of any important triggers you don't want to permanently jassify. I make a simple trigger with a line that contains what I'd need to do and convert it:
  • Events
  • Conditions
  • Actions
    • Unit Group - Clear Spell_Targets[(Integer A)]
 
Level 4
Joined
Dec 24, 2016
Messages
42
Alright Everyone. Just a quick thank you to all those who have contributed. It seems to work now and I would like to let everyone know that you have all helped me to create something that has lots of potential of being fun.

Have a good day everyone :D
 
Status
Not open for further replies.
Top