• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[General] Recycling variables to other spells

Status
Not open for further replies.
It's not really bad. However do note that arrays (no matter what size you set them) have 8192 (or so) slots. Unless you need it really much, it's probably better to use different variables.
You would also have to have a system for managing all this so that your code doesn't replace one unit by another inside the array by accident.

I do advise using temporal variables tho. Temporal variables are variables that get something assigned into them, that something is used immediately and then discarded - they do not save stuff for any period of time.
An example is creating unit at location:
  • Set loc = *somewhere* //create location
  • Unit - Create unit at loc //immediately use it
  • Custom script: call RemoveLocation(udg_loc) //destroy it to prevent memory leak
The advantage of this? You can use these temporal variables anywhere in your code, because they don't save anything for any length of time, there is no need to worry about accidently overwriting what's inside them.
 
You should recycle variables whenever possible. An example is what I refer to as "register variables" which are global variables that are used instantly in place of locals. They are perfectly safe to use everywhere as long as any actions run while they are in use will not result in their use in another thread.
 
Status
Not open for further replies.
Back
Top