Variablols

For discussions regarding skinning and mapmaking for Warcraft 3.

Moderator: Moderators

Variablols

Postby WatermelonMan » Fri Aug 08, 2008 6:15 pm

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.
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Fri Aug 08, 2008 10:39 pm

globals don't leak since they never lose scope
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby Dr.Willy » Sat Aug 09, 2008 3:17 am

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.
User avatar
Dr.Willy
 
Posts: 813
Joined: Sun Jul 02, 2006 11:23 pm

Re: Variablols

Postby WatermelonMan » Sat Aug 09, 2008 3:40 pm

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.
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Drain_Pipe » Sun Aug 10, 2008 6:42 pm

using a global is also good for transferring between maps. I learned that the hard way...
-Drain Pipe Out-
Drain_Pipe
 
Posts: 640
Joined: Sat Jul 29, 2006 9:16 am

Re: Variablols

Postby WatermelonMan » Tue Aug 19, 2008 6:52 pm

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?
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Wed Aug 20, 2008 5:01 am

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.
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby WatermelonMan » Wed Aug 20, 2008 3:27 pm

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 :(
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Thu Aug 21, 2008 4:45 am

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.
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby WatermelonMan » Thu Aug 21, 2008 4:49 pm

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)

Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Tirion » Thu Aug 21, 2008 9:42 pm

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.
Image
User avatar
Tirion
 
Posts: 413
Joined: Mon Jul 03, 2006 1:27 am
Location: Lurking

Re: Variablols

Postby Iam2good4u2c » Fri Aug 22, 2008 12:23 am

Did anyone notice the last four letters of the thread name?
User avatar
Iam2good4u2c
 
Posts: 294
Joined: Fri Apr 25, 2008 9:39 am

Re: Variablols

Postby Dr.Willy » Fri Aug 22, 2008 1:36 am

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...
User avatar
Dr.Willy
 
Posts: 813
Joined: Sun Jul 02, 2006 11:23 pm

Re: Variablols

Postby WatermelonMan » Fri Aug 22, 2008 5:09 pm

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?
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Sun Aug 24, 2008 1:56 am

The point will leak. You shouldn't use the GUI if you're worried about leaks
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby WatermelonMan » Sun Aug 24, 2008 8:31 pm

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.
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Mon Aug 25, 2008 4:34 am

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
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby Cassiel » Mon Aug 25, 2008 5:03 am

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.
User avatar
Cassiel
 
Posts: 5083
Joined: Wed May 31, 2006 2:12 pm

Re: Variablols

Postby WatermelonMan » Mon Aug 25, 2008 4:32 pm

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.
Image
WatermelonMan
 
Posts: 676
Joined: Tue Aug 08, 2006 3:10 pm

Re: Variablols

Postby Kaz » Mon Aug 25, 2008 7:57 pm

I switched to JASS to make my stupid first map work the way I wanted to
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm

Re: Variablols

Postby Boolerian » Mon Aug 25, 2008 9:18 pm

And what was your stupid first map?
User avatar
Boolerian
 
Posts: 138
Joined: Tue Mar 20, 2007 12:06 am

Re: Variablols

Postby Kaz » Tue Aug 26, 2008 8:07 am

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
Kaz
 
Posts: 2984
Joined: Thu Jul 06, 2006 11:04 pm


Return to Custom Mapmaking

Who is online

Users browsing this forum: No registered users and 1 guest