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

[General] Recycling variables to other spells

Status
Not open for further replies.
Level 25
Joined
Sep 26, 2009
Messages
2,383
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.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
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.
Top