Page 1 of 1

Variablols

PostPosted: Fri Aug 08, 2008 6:15 pm
by WatermelonMan
In a situation where a trigger is handling the same unit multiple times, you can set it as a variable like 'unit 1' and then use that variable instead of referring to "Unit 0012 <gen>" over and over. I'm not talking about a triggering unit, but a unit that has been pre-placed in the map. If you refer to it as "Hero 0012 <gen>" will that cause a leak or slow anything down, or does it even make a difference? Leak checker says it doesn't create a leak but I'm not sure it's telling the truth.

Re: Variablols

PostPosted: Fri Aug 08, 2008 10:39 pm
by Kaz
globals don't leak since they never lose scope

Re: Variablols

PostPosted: Sat Aug 09, 2008 3:17 am
by Dr.Willy
WatermelonMan wrote:... you can set it as a variable like 'unit 1' and then use that variable instead of referring to "Unit 0012 <gen>" over and over.

"Unit 0012 <gen>" is just a global variable created by the editor.
I would however suggest to use a udg, because if you ever want to change that unit, it'll be way easier with a udg and might save you a lot of clicking.

Re: Variablols

PostPosted: Sat Aug 09, 2008 3:40 pm
by WatermelonMan
Well I only did it once, but since it triggers often I was just worried that my already horrible map could get worse. Thanks guys.

Re: Variablols

PostPosted: Sun Aug 10, 2008 6:42 pm
by Drain_Pipe
using a global is also good for transferring between maps. I learned that the hard way...

Re: Variablols

PostPosted: Tue Aug 19, 2008 6:52 pm
by WatermelonMan
If I use a variable in <trigger x> and remove it in <trigger y> would that still create a leak? Do I have to remove it in the trigger that I created it in?

Re: Variablols

PostPosted: Wed Aug 20, 2008 5:01 am
by Kaz
You're getting two different things mixed up. A handle will leak when you lose reference to it without destroying it and it's no longer needed (e.g. a location). This is because there is no garbage collection in JASS. A handle variable will leak when it loses scope and it's not pointing to null. This is because JASS is fucking retarded.

Since global variables never lose scope, the second type of leak is impossible in the scenario you suggest. Only a global variable can be accessed by two different functions. Even two instances of the same function cannot access the same local variable as they both create their own copy.

Re: Variablols

PostPosted: Wed Aug 20, 2008 3:27 pm
by WatermelonMan
In trigger 1, if a unit casts an ability and I use variable x to mark that units position when it casted, and then I use a different trigger, trigger 2, to detect if the unit comes within range of variable x, and if it does, then trigger 2 kills the unit and removes variable x then does that creates a leak? I have to remove the location in the trigger that it is created in? But if variable x were a unit then that does not create a leak?

I don't entirely understand :(

Re: Variablols

PostPosted: Thu Aug 21, 2008 4:45 am
by Kaz
That variable is global. You only need to destroy the location (i.e. RemoveLocation) once you no longer need it and before you use the variable for another location. For temporary dummy casters, I recommend giving them a timed life of a few seconds so they disappear on their own.

Re: Variablols

PostPosted: Thu Aug 21, 2008 4:49 pm
by WatermelonMan
Alright cool, thanks. But on another note: what about unit groups? I've heard that unit groups cause leaks, what exactly about them do, assuming that they do in fact cause leaks?

this kid says that they do

emjlr3 wrote:Unit Groups

Code:

Unit Group Bad
Events
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)

Now this will leak memory for every unit picked, which, depending on how many times this is ran, can add up heavily.

Code:

Unit Group Good
Events
Conditions
Actions
Set Temp_Group = (Units in (Playable map area))
Unit Group - Pick every unit in Temp_Group and do (Actions)
Loop - Actions
Unit - Kill (Picked unit)
Custom script: call DestroyGroup (udg_Temp_Group)


Re: Variablols

PostPosted: Thu Aug 21, 2008 9:42 pm
by Tirion
Unit groups will leak. A group is created to hold all of the units that you want to loop through. Just like locations, the group will stay in memory until you destroy it, and if you lose reference to it it will just take up space and be useless.

I never see anyone use blizzard's global that they have for this, but you should be able to put the line
Code: Select all
set bj_wantDestroyGroup = true

before any Pick every unit in ... blocks and that will tell the ForGroupBJ function to destroy the group once it's done with it.

Re: Variablols

PostPosted: Fri Aug 22, 2008 12:23 am
by Iam2good4u2c
Did anyone notice the last four letters of the thread name?

Re: Variablols

PostPosted: Fri Aug 22, 2008 1:36 am
by Dr.Willy
Iam2good4u2c wrote:Did anyone notice the last four letters of the thread name?

Yes, but noone thought it was funny enough to mention it.
Until...

Re: Variablols

PostPosted: Fri Aug 22, 2008 5:09 pm
by WatermelonMan
i'm hurt, but thanks for the info Tirion :D :o :) :lol: :D :wink: :)

edit: so when you "set unitgroup1 = all units in range of point" that doesnt leak?

Re: Variablols

PostPosted: Sun Aug 24, 2008 1:56 am
by Kaz
The point will leak. You shouldn't use the GUI if you're worried about leaks

Re: Variablols

PostPosted: Sun Aug 24, 2008 8:31 pm
by WatermelonMan
meh, that's like telling a high school student in art 1 that they shouldn't use water colors if they want their paintings to look realistic. JASS would be more efficient, it just wouldn't be efficient for me to learn JASS.

Re: Variablols

PostPosted: Mon Aug 25, 2008 4:34 am
by Kaz
Which is of course something based on absolutely nothing except misconceptions that you told yourself. People use vJass nowadays and it's extremely simple and efficient

Re: Variablols

PostPosted: Mon Aug 25, 2008 5:03 am
by Cassiel
WatermelonMan wrote:meh, that's like telling a high school student in art 1 that they shouldn't use water colors if they want their paintings to look realistic. JASS would be more efficient, it just wouldn't be efficient for me to learn JASS.

Actually plain JASS is simpler than the GUI.

Re: Variablols

PostPosted: Mon Aug 25, 2008 4:32 pm
by WatermelonMan
Kaz wrote:Which is of course something based on absolutely nothing except misconceptions that you told yourself. People use vJass nowadays and it's extremely simple and efficient


No, I'm saying that there is no point for me to learn JASS because I already know GUI and I don't plan on going any further than my stupid map, I don't want to be programmer, I don't want to make games, I don't want to do anything associated with any of the above I'm just doing it because it's a source of amusement.

Cassiel wrote:Actually plain JASS is simpler than the GUI.
You're absolutely right.

Re: Variablols

PostPosted: Mon Aug 25, 2008 7:57 pm
by Kaz
I switched to JASS to make my stupid first map work the way I wanted to

Re: Variablols

PostPosted: Mon Aug 25, 2008 9:18 pm
by Boolerian
And what was your stupid first map?

Re: Variablols

PostPosted: Tue Aug 26, 2008 8:07 am
by Kaz
Turf war. I needed the ability to dynamically create triggers during runtime which the GUI won't let you do at all even though it's trivial in JASS