HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

arrays for dummies [tutorial]

12-29-2002, 11:08 PM#1
Azumarril
What is an array?
ar·ray: A set of data items of a single type in which item position is designated by an integer from zero to n.

yea, nice but why would i want to use an array?

it's a way to put multiple values into one thing. like different results to choose from.
example: you are asked to make a script to generate a random message.

here is non array example:
Code:
set iRand = (random integer number between 1 and 3)
// random #
if (iRand Equal To 1) then do (Set sMessage = hi) else do (Do nothing)
// if iRand is 1
if (iRand Equal To 2) then do (Set sMessage = hello) else do (Do nothing)
//2
if (iRand Equal To 3) then do (Set sMessage = sup) else do (Do nothing)
//3
pretty hard to make huh? well not as easy as i'm gonna show you.
you call arrays by using arrayname[arrayvalue] and arrayvalue is an integer.
the way to arrays =P:
Code:
set iRand = (random integer number between 1 and 3)
// set irand = 1 2 or 3
set saResult[1] = hi // value 1
set saResult[2] = hello // value 2
set saResult[3] = sup // value 3
set sMessage = saResult[iRand] //load saResult[iRand] ex: if irand was 1 it would load saResult[1]
cool huh? there might be other uses. and most variable types can be arrays =D
are arrays worth it?
sometimes i usually use arrays for multiple values and not seperate values. and just to make my scripts more compact. especially if i'm dealing with players.

note: mods if you want to unstick this that's fine
note2: i was using
PHP Code:
and 
to color code the trigger code
12-30-2002, 07:36 AM#2
DemonicSoul
also you can do some handy thigns such as

set integer[1] = integer[1] + 1

then say that integer[1] was 5 it would then be 6

or using it for every player instead of making lots of different variables

of course..... this would be scratching the surface.... but it could help some newbs

Fixed by Azumarril
12-30-2002, 05:02 PM#3
FyreDaug
Actually Demonic, you're wrong about that. the plus 1 wouldn't be inside the brackets, it would be outside. And you can do this with any number variable, be it real, integer etc
12-31-2002, 03:51 PM#4
DKSlayer
FyreDaug, He was adding the 1 to the variable integer[1]. So yes he needs the 1 in the bracket. Like a counter for a loop.
Yes, array's can be very useful. I hope to be adding a Big Variables, tutorial to the JASS/AI Tutorial&FAQ. I should get done soon with it.
Thanks
DKSlayer
12-31-2002, 05:59 PM#5
FyreDaug
His psot was modified after I posted that, and assuming because you said it was correct, it was modified before you posted.

It is correct now.
12-31-2002, 07:04 PM#6
DemonicSoul
oh well whatever i didnt check or anything but they get the picture... can arrays be used in events?
12-31-2002, 08:14 PM#7
Guest
I remember staredit...no variables, no arrays.....It's like you have to be a programmer to make a decent map now. I don't mind (It's a lot more flexible for us), but for someone that has never programmed this would suck.
12-31-2002, 08:17 PM#8
Azumarril
how the heck could you make a map without variables!?!?!?
that's like half immpossible! unless your some kinda
"no varaiable" wizard heh
---
and for the post i edited was it right the first time or do i have it correct.
12-31-2002, 08:27 PM#9
Guest
Hey, maybe I missed something back then (StarEdit).....but wasn't it just using objects in the triggers? I don't remember any variables that could be directly manipulated. Great...now you've got me thinking. Thanks a lot, pal.....heh.
01-01-2003, 07:20 AM#10
DemonicSoul
Quote:
FyreDaug, He was adding the 1 to the variable integer[1]. So yes he needs the 1 in the bracket.



Quote:
can arrays be used in events?



Quote:
It's like you have to be a programmer to make a decent map now

well no not really.... u just havew to work hard and maybe get a programmer to write some stuff for u it its really advanced
01-04-2003, 06:49 AM#11
Electromancer
Star edit had variables, but they were limited to 2 things, on and off. I remember it so well, If Switch 1 is on If Switch 2 is on If Switch 3 is off create marine. Ah, found memories of becoming pissed when you had to make 50 damn switches just so it would give them a message. Those were the days. And you dont have to be a programmer. It helps, but you dont gotta be. I learned it in an hour, or the majority. I even wrote a few trigs for Ultimate RP (if any of you have heard of that.) But now im working on spells and such. They are more fun.
01-06-2003, 12:37 PM#12
Guest
Switches....yeah, ok I remember those.

I guess you don't have to be a programmer to make a map, but more and more everyone has to learn these programming concepts. It is necessary for in-depth editing I suppose but...I wonder what the next editor will look like.
01-07-2003, 10:04 PM#13
DemonicSoul
i dont know why i made that last post... i think i knew the answer

to use variables in events got to convert to custom text and just replace what was refered to in the event with the internal name of your variable
01-14-2003, 07:31 PM#14
Milkman
That tutorial wasnt really for dummies was it since it was written in code, it would been a lot easier for "dummies" to understand if you put an explanation or two in there. But who am I to complain? It probably helped someone...
01-14-2003, 09:39 PM#15
Azumarril
i ment that to be funny cause haven't you seen the "for dummies" books? hmm i thought i closed this thread.