Edited by Smilodon, 07 October 2010 - 02:27 AM.
Arrays
#1
Posted 06 October 2010 - 05:42 AM
#2
Posted 06 October 2010 - 06:05 AM
array_name[0] = 4; array_name[1] = "Dave"; array_name[2] = "Good";
Recognise it yet?
#3
Posted 06 October 2010 - 07:40 AM
An "integer" is just a name for a special group of numbers, just like a square is a sub-form of the group rectangles.Same deal with integers.
An integer is just a value with no fractional part (nothing right of the decimal dot), and in computer terms often being defined as having a limited range. For a byte (8 bits) the integer either ranges from -128 thru +127 (signed) or 0 thru 255 (both ends included). For a Word (double-byte) that would be -32768 thru +32767 or 0 thru 65535.
Hope that clarifies it.
P.s.
In GM all numbers are stored as arrays : the variable "MyVar" is the same as "MyVar[0]". This is why you can use "view_xview" (and not "view_xview[0]") without a problem.
#4
Posted 07 October 2010 - 02:07 AM
yep i get it. I'm not sure what the heck that could be used for though. Just trying to imagine some guy running at a speed of 4 and another saying dave or something.An array looks like this:
array_name[0] = 4; array_name[1] = "Dave"; array_name[2] = "Good";
Recognise it yet?
#5
Posted 07 October 2010 - 02:09 AM
Yeh i knew the last bit, but thanks 4 the rest. lol can't believe i've used GM morethan 3 years but i don't know crap like this.Hope that clarifies it.
P.s.
In GM all numbers are stored as arrays : the variable "MyVar" is the same as "MyVar[0]". This is why you can use "view_xview" (and not "view_xview[0]") without a problem.
#6
Posted 07 October 2010 - 06:44 AM
You're welcome.Yeh i knew the last bit, but thanks 4 the rest.
You mean you did not know the words used, by others, to describe it.lol can't believe i've used GM morethan 3 years but i don't know crap like this.
The description is mostly the easiest part. Understanding the concept (which you allready knew!) is the hardest part.
Guess whom I rather talk to : the person who knows the description but does not understand the its working, or the person who knows the working but does not know how others describe it ?
#7
Posted 07 October 2010 - 09:28 AM
The advantage comes in for loops, and a few other situations. Let's say you stored all of the high scores in a file, one high score per line, you could use an array to read each of the lines using a for loop. line[0] would be the first line, line[1] the second, etc.yep i get it. I'm not sure what the heck that could be used for though. Just trying to imagine some guy running at a speed of 4 and another saying dave or something.
Then to draw the high scores, you could just do:
for (i=0; i<10; i+=1)
{
draw_text(x,y+i*20, string(line[i]));
}
It can save you many lines of code, and saves you coming up with a new variable for every line of the text file.
Imagine you didn't know before hand how many lines the text file had, arrays really come in handy then too.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











