Tutorial Variable Introductory

Ryuu

I am back with Chocolate (:
Reaction score
64
VARIABLE INTRODUCTORY

When you hear the word 'variable', does it spook you a little? Maybe.
If you are one who dislike variables and believe that you can go and make a map better than DotA without using variables, go ahead. I see you'll come crying for help days later.

And when you do need help, this tutorial is never going to leave you.

Contents
  1. Introduction to Variables
  2. Using Variables
  3. Introducing and Using Arrays

Introduction to Variables
Variables doesn't only exist in WarCraft. It existed long long ago (not too long), and I don't know who invented it, but I guess it would be a mathematician.

Q: Yo.
A: WHA.. Who are you?

Q: I'm your mother.
A: I see.. HEY!

Q: Call me the Invisible Person.
A: OK.

Q: I wanna ask you some questions.
A: Sure.

Q: What are variables?
A: A variable store information, and it can store any information. But [Courtesy of Romek] each variable can only store 1 piece of information, unless it's an array variable, which I will later explain.

Q: What kind of information do variables store?
A: Variables store WarCraft information. For example, there is the Unit, which you can set the variable to a unit in the beginning of the game and then create it at the end of the game, all using only one variable.

Q: What are variables used for, besides storing information?
A: Variables are wonders. For example, you can remove leaks using Custom Script, do actions which no preplaced information can. For example, there is no action called "Create Dialog". Therefore, by creating the variable, you have already created the dialog.

Q: What other usefulnesses?
A: Do you need a time machine?

Q: Of course I need! But it doesn't exist, unfortunately.
A: The only 'time machine' invented now is variables. As I have explained earlier, I will now emphasize more on it. Say, you need the player to pick a unit at the beginning of the game. Now the player chose the unit, and you want to spawn it as a 'boss creature' for the end of the game. But how do you even transport the information from 'beginning of the map' to 'end of the map'? Easy.

Q: You haven't stated how.
A: The answer is to use the [first word of the tutorial's title].

Q: Ermm.. that would be.. [Tutorial]?
A: No. The answer is using "Variables".

Q: I see.
A: Glad you do.

Q: ... ... ... ...
A: ... ... ... ...

Q: Let's get on to the next topic now.
A: Sure.

Using Variables

Q: So now I know what are variables, how can I use them?
A: First of all what you need to do is to understand the variable -

Q: I already understood variables!
A: I meant you need to understand the variable-creating window.

Q: Oh..
A: Yes.

Q: OK, so what about the variable-creating window?
A: I assume you're already in World Editor.

Q: But I'm not!
A: Then get in now.

Q: I'm in.
A: Good. Now fire up your Trigger Editor (F4) and press the yellow 'X' button at the top of the Trigger Editor. You should see this window:

Variablescreen.jpg


Q: Yup, I saw it. So now.. what?
A: First, I'll give you a new picture. Take a look at what each button does.

VariablescreenArrowed.jpg

1 - Opens up a small dialog. This is useless as all the buttons are displayed on the main Variable screen.
2 - Cut. This function removes the selected variable and you can make it appear elsewhere using the 4th function.
3 - Copy. This function make the selected variable remain and you can duplicate it using the 4th function.
4 - Paste. Using the Cut or Copy the function, you can make the cut or copied variable appear.
5 - Undo. Undo the previous change you made to the Variables screen.
6 - Redo. Redo the previous change you made to the Variables screen.
7 - New Variable. Self-explaining, creates a new variable.
8 - Edit Variable. Self-explaining, edits the selected variable's details.
9 - Delete Variable. Self-explaining, deletes the selected variable.
10 - Variable name. Name of the variable.
11 - Variable type. The type of information that the variable is storing.
12 - Initial Value. The first information to be held in the variable. Usually left blank.
13 - OK. Confirms all variable details and exit the Variable screen.
14 - Cancel. Exit the Variable screen without confirming any changes made from previous save using 'OK'.

You with me?

Q: Yeah I am.
A: OK. There are other screens within the Variable screen too, such as the Variable Detail screen. This screen is accessed by either clicking on New Variable or Edit Variable.

VariableDetailscreenArrowed.jpg

1 - Variable name. Your desired name of the variable that you want.
2 - Variable type. Your desired type of information that you want the variable to store.
3 - Clear Value. If any Initial Value is attached to the variable, this button will clear that Initial Value.
4 - Initial Value. The first information that you want the variable to hold. Usually left blank.
5 - OK. Confirms all variable details and exit the Variable Detail screen.
6 - Cancel. Exit the Variable Detail screen without confirming any changes made to the variable.

Q: Any more screens?
A: Nope, no more. So did you understood them?

Q: Yes, of course.
A: OK. Now let's begin making a simple trigger using variables.

Q: OK.
A: First things first, you need to create a variable. Without closing the Variable screen -

Q: I closed it.
A: Open it up again.

Q: Done.
A: OK. Now in your Variable screen, click on the green 'X' and you should come into the Variable Detail screen. Fill in your Variable Name (mine is TestUnit), the Variable Type (make it Unit) and leave the others as it is, and then click on OK. Now your Variable screen should look something like this.

VariablescreenModified.jpg


Q: Yeah, mine looks something like that.
A: Cool. Now we create a simple trigger (I assumed you already know how).

Q: What are we gonna do?
A: We are going to create a Footman.

Q: Cool!! How do I do this?
A: Hehe, relax. Patience, dude. Now, I'm not going to introduce must above triggers, so you must learn yourself on how to make this:

CreateUnitTrigger.jpg


Q: Made it!
A: Nice. You should realise that the above action leaks.

Q: What are leaks?
A: Leaks are what happens if you don't have a reference to an object. Then it will take up your Virtual Memory. When lots of leaks are in the game, it will start to cause lag, and if there is too much lag, your WarCraft will crash, or worse, your computer will restart. Therefore we need to remove them. And, thanks to Trollvottel for reminding me, leaks are unused objects with no reference to them. And leaks are not the objects, but what happens if you dont have a reference to the objects.

Q: What type of objects leak?
A: (For GUIers like you and me) Special Effects, Points, Unit Groups, Player Groups (NOT All Players!) and Floating Texts (If you don't disable permanence and give it a life time).

Q: That doesn't sound like you knowing those stuff. Who gave you the information? :p
A: Uh... Darthfett :banghead:

Q: OK... so how do I remove the leaks?
A: Requires a mustard seed's knowledge of JASS.

Q: :eek: That's a lot! I'm never going to create a unit!
A: A mustard speed is a microscopic seed.

Q: Oh. Sorry about that.
A: Never mind.

Q: So.. how do I remove the leak?
A: There are two ways you can convert from GUI to JASS. The first way is to convert the whole trigger into JASS, and the second is to convert only an action into JASS. We'll be using the latter, but we're not exactly 'converting'.

Q: Why not?
A: Because this 'leak removal' function is only a function available in JASS, but we could use a GUI function which allows you to type JASS scripts in it.

Q: That's cool!
A: Don't get so happy.

Q: Why not?
A: Because learning JASS is not an easy thing. But since I'm guiding along, it may be easy to you.

Q: Hooray!
A: Sigh.. Anyway, add this action below the trigger you just created.

CustomScript.jpg


Q: ...
A: I knew it.

Q: How do I MAKE that?
A: Well okay first of all you got find the function 'Custom script'.

Q: Found it, now what?
A: Type in what you see on the action in the screenshot I gave above.

Q: I'm lazy to type it in, give me the code so that I can copy and paste.
A: Sigh...
call RemoveLocation( udg_TestPoint )

Q: OK, done.
A: Realise that in the above action, there is this word called 'TestPoint'.

Q: Suspicious.
A: Seriously.

Q: Okay, so is TestPoint a variable?
A: For the first time, you got it right!

Q: Me no first time...
A: Whatever. Now using the knowledge I gave you above, create a Point Variable for me with the name TestPoint.

Q: Done.
A: Good job.

Q: So what's this 'TestUnit' used for? Fun, laughter, peace and joy?
A: No! It's not there for fun, laughter, joy and peace.

Q: PEACE and JOY. Not JOY and PEACE.
A: OK, whatever. Now we are going to change some things: look into the Unit Create action.

Q: OK, must I change anything?
A: I just said it.

Q: I wasn't listening.
A: Aack. Did you focus for all the things I thought you?

Q: Yawn.. Huh? What?
A: *Slams hammer on your head*

Q: Yawn.. OUCH! What?
A: Listen.

Q: OK.
A: So we have to change something in the Unit Create action. But what is it? Obviously it is the Point Variable we need to change, because we just created a new Point Variable.

Q: OK, so how do I change it?
A: Simple. Double click the Unit Create action, click on the blue underlined field with the (Center of (Playable map area)) in it, and then click the dot beside 'TestPoint'.

ChangePoint.jpg


Now click OK all the way.

Q: Done.
A: Right, now you should have the following trigger:

TriggerModified.jpg


Q: Yes I have. But something weird.. it feels as if something is missing...
A: Of course something is missing! Like I said earlier, a variable is one who stores information. But we haven't stored any information yet.

Q: We haven't? But.. then.. what's that on the Variable Detail screen?
A: That's the TYPE of information.

Q: Oh! So right now we need to set (Center of (Playable map area)) to TestPoint!
A: Almost right. Actually, we need to set TestPoint to (Center of (Playable map area)).

Q: And.. how?
A: Do I HAVE to provide you everything? -.-"

TriggerModified2.jpg


Realise the TestPoint is above the Unit Create action. It is because it needs to be above. If you would to set it below, it would go like this: I will create Footman for Neutral Passive at <nowhere> facing Default building facing degrees, then I will set the TestPoint to (Center of (Playable map area)). It is 'nowhere' because TestPoint isn't set to anything YET.

If you were to put it above.. it would go like this: I set the TestPoint to (Center of (Playable map area)), then I will create Footman for Neural Passive at (Center of (Playable map area)) facing Default building facing degrees.

Q: Yes! I got it! But how does the trigger works?
A: If you look carefully, at 0.00 seconds, it will create a Footman for Neutral Passive at Center of Playable map area (which is TestPoint), and then it will destroy the point, removing the leak. It's all simultaneously done.

Q: Wow! So then, what is the TestUnit used for? (Second time asking)
A: Apologies for not answering your question earlier. Now we set the TestUnit variable to the Footman we have just created.

Q: You-
A: I know what you need.

TriggerModified3.jpg


Q: Thanks.
A: No problem.

Q: OK so now I got all four actions, why do we actually need to set TestUnit to the Footman created?
A: Because we are going time travel.

Q: Wow..
A: Yes. But not something to be 'wow'ed at if you're good in variables.

Q: So how do we travel in time?
A: You must learn how to duplicate units first. After the fourth action, add a 60 second Wait and then repeat the first three actions. Now test the map.

Q: HEY!!! TWO FOOTMANS ARE ON MY MAP!!
A: Very cool. So, we know that our Footman here went 'duplicating', but we don't know it went 'time travelling'. So now delete the wait and the last three actions, leaving only the original 4 actions.

TriggerModified3.jpg


Q: Then?
A: Then add a Wait for 5 seconds after the fourth action. Using the Unit - Hide action, hide TestUnit and then wait for a further 60 seconds, and then using the Unit - Unhide action, unhide TestUnit.

Q: Confusing.
A: Here.

TriggerModified4.jpg


Now test it.

Q: Ah! My Footman disappeared!
A: Wait a little while.

Q: HEY! It reappeared!
A: Yes, it did. Now we know that all we did was hide and unhide TestUnit, but what if you KILLED TestUnit and for some reason, he reappeared?

Q: The Grave Rebirth!
A: Something like that.

Q: How do I do that?
A: Easy. Take away the last 3 actions (your fifth action should now be a 'Wait 5.00 seconds' action). Add in (Unit - Kill TestUnit) and then (Wait 60.00 seconds). Then, repeat the first action, and (Unit - Create 1 (Unit-type of TestUnit) for Neutral Passive at TestPoint facing Default building facing degrees). And don't forget that leak!

Nevermind, I'll show it to you instead.

TriggerModified5.jpg


Now test.

Q: Same thing as the Hide/Unhide trigger.. just that it killed and revived instead of hide and unhide.
A: Yes its the same.

Q: So what time travel is there? This stuff is lame.
A: You havent seen the real deal yet! In the second action of your trigger, instead of using Footman, try using Knight, Peasant, Rifleman, etc. Just change that field and nothing else! Now test it.

Q: WHAT THE-! I used Knight and the Knight got killed and then got revived! It was like he had a duplicate in the future and then he just came out like that! It's like time travel!
A: Of course. Now try using the previous two triggers using Peasant and Rifleman and see what happens (remember, change only the second action, nothing more).

Q: The second trigger worked as if TestUnit really time-traveled! But for the first trigger.. No.. A Footman instead of a Rifleman was created.
A: Of course. Because you are using a raw value that was not set to any variable (in your first trigger, look into the 7th action. It says 'Create Footman'. Whereas in your latest trigger, it says 'Unit-type of TestUnit', and TestUnit is the unit that is created in the second action.

Q: I see...
A: Let's go into arrays now.

Introducing and Using Arrays

Q: [Off-topic] I heard rumours about this cool, time-saving device known as 'Arrays'. Does it exist?
A: Well certainly. And remove that Off-topic sign.

Q: Why?
A: Because it is not off-topic.

Q: You mean, it's got to do with WARCRAFT? TRIGGERS? VARIABLES?
A: Yup.

Q: AWESOME! Haha!
A: Yup.

Q: So what are arrays?
A: Let's say you cut an apple into three thirds. You pick up one third and you say that this is a part of an apple, but the juiciness and the taste of the apple is not split into three. It is the same with arrays and variables. And array can be split into hundreds of parts. But the information is not split into hundreds of parts. For example, your variable is a unit variable, and you make it an array variable, it's not going to split your unit into hundreds of parts.

Q: Let me get this straight. So arrays are like variables except they are split from variables?
A: Yes! Each array is a variable by its own. An array is identified by the brackets [1] after the variable name. With arrays, more things are more awesome. For example, if you want to set every unit variable array to the same unit, and you want to set 100 arrays, you don't go

Set UnitVar[1] = Unit
Set UnitVar[2] = Unit
Set UnitVar[3] = Unit
Set UnitVar[4] = Unit
Set UnitVar[5] = Unit
Set UnitVar[6] = Unit
Set UnitVar[7] = Unit
Set UnitVar[8] = Unit
Set UnitVar[9] = Unit
Set UnitVar[10] = Unit

Instead, you go something like this.

Trigger2.jpg


Q: Real confusing.
A: Don't worry. I'll explain all this in a while.

Q: Okay.
A: In order for WarCraft to identify the array, you need integers to find out which 'part' of the variable does the array belong to. Like if you cut the human body into three, you take the head and say that this is the head. But an array doesn't have a body, head, tail, limbs, neck, etc. It is only identified by integers.

Q: Go on..
A: For example, you make a variable array called 'Array'. Array[1] is the FIRST part of the variable. And Array[2] is the SECOND part of the variable. And then, Array[10] is the TENTH part of the variable. Now we know that each array is a variable by itself, so if you have Array[1] to Array[100], that means there are 100 variables in one variable. That basically means, 100 information is stored in one variable.

Q: Cool!
A: The trigger I posted above gives a loop that has 100 (Integer A)s. That means its a loop that is recurring 100 times. Therefore it's a good action to use if you want to set 100 arrays to 100 things.

Q: And what's the Integer A?
A: Like arrays, Integer A is used to identify the current number of the loop recurring. That means, every time it recurs, Integer A becomes (Integer A + 1). At first, Integer A is set to the first number of the action (the '1' as seen here):

For each (Integer A) from 1, do (Actions)

Q: Awesome! Now get back on topic, about arrays. What are the cons for arrays?
A: Well, an array is stuck to the variable type that variable is. For example, if the variable is a unit variable, all arrays of the variable can only store unit information.
Editor's note to readers: If you have any cons of arrays to contribute, please tell me by replying in this thread or by PMing me.

Q: That's it?
A: That's it.

Q: Now let's do some time traveling.
A: Wait, you haven't understood arrays enough yet.

VariableDetailscreenArrowed2.jpg

1 - A boolean that allows you to specify if the variable is an array variable or not.
2 - Ask me.
(The information below is given by Darthfett and Romek)

Q: That's the second time I saw the Variable Detail screen.
A: It's a different one.

Q: Oh..
A: Yes.

Q: What is the SIZE for?
A: Basically, the SIZE of the array only affects certain variables.

Q: Like?
A: Like Timers and Dialogs. You know, those stuff that can't be created through actions.

Q: Go on..
A: The maximum number of the array you can get to the highest is 8191.

Q: Continue.
A: So if the variable is like timers and dialogs and you set the SIZE to 10, only arrays 1-10 will be set to something. 11-8191 will be null, and you can't you use them in any way unless you know JASS.

Q: I need to know more.
A: Let's say you have a variable named Timer, which is a timer array variable, and the SIZE is set to 10. So you now you do a trigger like this:
Code:
Set Timer[1] = [COLOR="Red"][B][Timer1][/B][/COLOR]
Set Timer[2] = [COLOR="Red"][B][Timer2][/B][/COLOR]
Set Timer[3] = [COLOR="Red"][B][Timer3][/B][/COLOR]
Set Timer[4] = [COLOR="Red"][B][Timer4][/B][/COLOR]
Set Timer[5] = [COLOR="Red"][B][Timer5][/B][/COLOR]
Set Timer[6] = [COLOR="Red"][B][Timer6][/B][/COLOR]
Set Timer[7] = [COLOR="Red"][B][Timer7][/B][/COLOR]
Set Timer[8] = [COLOR="Red"][B][Timer8][/B][/COLOR]
Set Timer[9] = [COLOR="Red"][B][Timer9][/B][/COLOR]
Set Timer[10] = [COLOR="Red"][B][Timer10][/B][/COLOR]
Set Timer[11] = [COLOR="Red"][B][Timer11][/B][/COLOR]

Timer[11] here will be set to null, and if you continue setting Timer[12], [13], [14] and so on, they all will be set to null too.

Q: Unless you know JASS.
A: That's what I said.

Q: So what I understood from this point of time now is that the maximum number of arrays you can reach is 8191, and that the SIZE of the array only affects certain variables that cannot be created through triggers. Am I right, or am I right?
A: Right.

Q: So that means you can't set any array higher than the SIZE of the variable? Like if the SIZE is 100, I can't set anything like this: Variable[101], Variable[102]?
A: Absolutely right. Also, for other variables like Booleans, Units, Reals, Integers, etc, the array can be used up to 8191 without setting the size. So if you set the size to 0, the default value of the integer (for example) will be null, but you can easily set it using the set variable action. Credit to Romek for this information.

Q: Oh I get it now. Let's carry on!
A: What do you want to learn about?

Q: Let's travel through time!
A: Then let us use just one variable to transport 10 units through time.

Q: AWESOME!!!
A: Totally.

Q: So.. how?
A: Well, firstly I'll be starting on a new trigger. Go into the Variable screen, and then create a new variable 'TestUnitArray' (Unit Array Variable). Create a trigger like this:

CreateUnitInArrayTrigger.jpg


Q: Got it! I tested it and, whala! 10 Footman came out!
A: Yup. Now we got to make use of the array variable.

CreateUnitInArrayTriggerModified2.jpg


Test it after making the trigger.

Q: Wow! 10 Footman came up one by one!
A: Excellent.

Q: Hey, I'm going off. I'm gonna make an excellent map better than DotA!
A: Bye.
_________________________________________________________________

That's it, folks. I hope you learnt at least something with my recorded interview with the Invisible Person. I don't mind criticisms, as this is my first tutorial with category 'Interviews'. Please comment on this. Thank you very much!

"Questions should be asked, and answers should be given."
QFT

"Variables are dumb. But since it is invented, we must live for its usefulness."
QFT
 

UndeadDragon

Super Moderator
Reaction score
447
Wow a big Q&A. Bigger than Ace's :p

>Is it just me, or is none of the images appearing?

No they are not.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
> No they are not.

Hold on lemme check 'em out.

EDIT:
Is it you can't put .png images on TH?

EDIT2:
OK! Images are up and working!
 

Exuro.

New Member
Reaction score
5
Holy crap thats one hell of a QA..

Damn i wish i had this when i first started using WE.. they just gave me such a headache hehe

Very nice work
 

Ryuu

I am back with Chocolate (:
Reaction score
64
Variables are a dumb invention. But, since it is invented, we must live for its usefulness. :p
 

Romek

Super Moderator
Reaction score
963
Seems like you're teaching a nursery child about variables.
And that image with all those numbers looks awfully confusing.

Also, did you have to compare what people make to DotA? :rolleyes:

Variables are a dumb invention. But, since it is invented, we must live for its usefulness.
Yeah... A World Editor without variables isn't a World Editor.
They make things so much easier. [del]We'd probably have to use gamecache to store everything.[/del] Wait... Even GameCache is a variable.
 

Trollvottel

never aging title
Reaction score
262
Q: What are leaks?
A: Leaks are stored 'something's that take up your Virtual Memory. When lots of leaks are in the game, it will start to cause lag, and if there is too much lag, your WarCraft will crash, or worse, your computer will restart. Therefore we need to remove them.

So if i create a unit it is a leak? no

Leaks are unused objects with no reference to them.

And leaks are no the objects, but what happens if you dont have a reference to the objects.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
> Seems like you're teaching a nursery child about variables.

I tried to make it as noob-friendly as possible.

> And that image with all those numbers looks awfully confusing.

Well, at least it has arrows with numbers pointing to them ;)

> Also, did you have to compare what people make to DotA?

Because DotA is too much popular, I just had to compare.. sorry.

> Leaks are unused objects with no reference to them.

Forgot to mention that only certain objects leak. I'll go update it.
 

Romek

Super Moderator
Reaction score
963

Ryuu

I am back with Chocolate (:
Reaction score
64
> Noobs != 3 year olds.

?

That's what makes it so confusing.

I don't know how to make it less confusing.
 

Exide

I am amazingly focused right now!
Reaction score
448
I'm guessing this is a good way to introduce someone to variables, which sure can come in handy around here. :thup:
However, you're forgetting the most important of variables: local variables!
You should also say something bad about global-locals or whatever those abominations are called..
-Then I'm happy. :p
 

Romek

Super Moderator
Reaction score
963
I'm guessing this is a good way to introduce someone to variables, which sure can come in handy around here. :thup:
However, you're forgetting the most important of variables: local variables!
You should also say something bad about global-locals or whatever those abominations are called..
-Then I'm happy. :p
I think he's focusing on GUI here.
I don't understand what's wrong with those global-locals.
Despite the fact that they can't be used in If/Then/Else and Loops, they work fine.

Oh btw:
2 - Not sure what is this used for. Usually left as it is.
Editor's note to readers: If you know what the SIZE is for, please tell me by repling in this thread or by PMing me.

That size is basically how many indices of the array will be initialized.
So, if you set the default value of the array to 10, and the size to 100, only indices 0 - 99 will have the value of 10.
And, no matter what you put there, the limit is 8191.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
I don't understand what's wrong with those global-locals.
Despite the fact that they can't be used in If/Then/Else and Loops, they work fine.

And the fact that you can only have one local global of each type maybe?

@Ryuu: Long tutorial is long (for something that very simple :p). Well explained and illustrated. Good job if I may say so.

Also a little side-note:

> Noobs != 3 year olds.

?

If you were a JASS-coder you would read that as "Noobs not Equal to 3 year olds." :p.
 

Romek

Super Moderator
Reaction score
963
Just some errors I found after reading the first few lines:
Q: What are variables?
A: Variables store information, and it can store any information. However, one variable is one variable, and cannot store more than one information, unless you use arrays, which I will introduce to you later.
That hardly makes sense. I think you mean something along the lines of "Each variable can only store 1 piece of information, unless it's an array"

Q: What kind of information do variables store?
A: Variables store WarCraft information. For example, there is the Unit, which you can set the variable to a unit in the beginning of the game and then create it at the end of the game, all using only one variable.
You can only set a unit variable to a unit which has been created.
So you can't store a unit variable, then create the unit at the end of the game.. o_O.

How can you store something which doesn't exist?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Your section on Memory leaks is missing something about which variable types have to be removed. For GUIers: Special Effects, Points, Unit Groups, Player Groups (NOT All Players!), Floating Texts (If you don't disable permanence and give it a life time), and possibly dummy units.

You may also want to say that they only need to be removed when you're done with them. (You don't have to create it, use it, destroy it, create it, use it, destroy it, create ... etc).

2 - Not sure what is this used for. Usually left as it is.
Editor's note to readers: If you know what the SIZE is for, please tell me by repling in this thread or by PMing me.

Basically, it pre-sets all the values of the array from 1 to the value you put here to "Initial Value:"

For Timers, Dialogs, Leaderboards, and Multiboards, this is mandatory, since in JASS you have to create these (in GUI there is no create function). The editor automatically creates them for you, as long as you set a default value for it.

For Units Groups and Player Groups, it is sometimes mandatory. Setting a Unit Group to Units in (Playable map area) doesn't require you to initialize it, since this will create a group with the units in it for you. However, when you use ___ Group - Add ___ to ___ Group, it assumes the group is already created, and simply tries to add something to the group. However, if the group is not initialized or is destroyed, there IS no group, and so it cannot perform the action. That's the long version.

Nice tutorial, though. I've had plenty of people ask questions, when they should have been smart enough to figure it out themselves. By making your tutorial this simple to understand, you completely eliminate the thinking process :rolleyes:.

Basic is good.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
Thanks for the comments you peeps. ;)

> However, you're forgetting the most important of variables: local variables! (Exide)

I'm no JASSer, so me don't know locals.

> I think he's focusing on GUI here. (Romek)

Yep.

> That size is basically how many indices of the array will be initialized. (Romek)

Sorry, but I still don't get it. :(

> Long tutorial is long (for something that very simple :p) (Larcenist)

Actually, no, to beginners variables isn't something very simple. I had a difficult time learning variables.

> That hardly makes sense. (Romek)

OK, I'll go change it.

> You can only set a unit variable to a unit which has been created. (Romek)

Yes. What I really meant was, you create a unit in the beginning of the game, set the variable to the unit, remove the unit, and then create it again at the end of the game.

> Basically, it pre-sets all the values of the array from 1 to the value you put here to "Initial Value:" (Darthfett)

Sorry but I really still don't get it. :(

> Your section on Memory leaks is missing something about which variable types have to be removed. For GUIers: Special Effects, Points, Unit Groups, Player Groups (NOT All Players!), Floating Texts (If you don't disable permanence and give it a life time), and possibly dummy units. (Darthfett)

My job isn't to teach about memory leaks. But since I came across that topic, I might as well teach a little. But will add which object causes leak.

Why is the whole thing Q&A? (quraji)

Don't know. The thought just came into my head. :p
 

Romek

Super Moderator
Reaction score
963
Ryuu said:
Sorry, but I still don't get it.
What exactly don't you get. It can't get any simpler than that.

Yes. What I really meant was, you create a unit in the beginning of the game, set the variable to the unit, remove the unit, and then create it again at the end of the game.
You can't recreate a dead unit (Unless it's a hero, or by spells such as Resurrection). You can however, set that variable to another unit later on in the game.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
Unit - Create 1 (Unit-type of (VARIABLE))

Actually, I just wanted to prove that with 'variables', you can 'resurrect through time'.

I know it's hard to understand, but please do.

> It can't get any simpler than that.

One thing, what are indices? :p
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Unit - Create 1 (Unit-type of (VARIABLE))

Actually, I just wanted to prove that with 'variables', you can 'resurrect through time'.

I know it's hard to understand, but please do.

> It can't get any simpler than that.

One thing, what are indices? :p

Indexes*

Let's say you have an Array of units called Units. In Unit[1], 1 is the index. Basically the integer you use to refer to the value.

So if I set size for a timer array to 10, it would go through indexes 1-10 (Timer[1],Timer[2]... etc) and sets them to CreateTimer()

Timer[11] through Timer[8191] would all be set to null (and you can't use anything higher than 8191). That means that you won't be able to use them in any way (unless you know JASS, of course).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top