Jump to content


Photo

Arrays


  • Please log in to reply
6 replies to this topic

#1 Smilodon

Smilodon

    GMC Member

  • New Member
  • 25 posts

Posted 06 October 2010 - 05:42 AM

I don't actually know what an array is but i've got this weird feeling i've been using them for ages without knowing. Same deal with integers. And before you say im a newb, i've been using GM for over 3 years, and have a pretty good knowledge of GML commands.

Edited by Smilodon, 07 October 2010 - 02:27 AM.

  • 0

#2 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 06 October 2010 - 06:05 AM

An array looks like this:

array_name[0] = 4;
array_name[1] = "Dave";
array_name[2] = "Good";

Recognise it yet? :)
  • 0

#3 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 06 October 2010 - 07:40 AM

Same deal with integers.

An "integer" is just a name for a special group of numbers, just like a square is a sub-form of the group rectangles.

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.
  • 0

#4 Smilodon

Smilodon

    GMC Member

  • New Member
  • 25 posts

Posted 07 October 2010 - 02:07 AM

An array looks like this:

array_name[0] = 4;
array_name[1] = "Dave";
array_name[2] = "Good";

Recognise it yet? :)

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.
  • 0

#5 Smilodon

Smilodon

    GMC Member

  • New Member
  • 25 posts

Posted 07 October 2010 - 02:09 AM

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.

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.
  • 0

#6 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 07 October 2010 - 06:44 AM

Yeh i knew the last bit, but thanks 4 the rest.

You're welcome. :)

lol can't believe i've used GM morethan 3 years but i don't know crap like this.

You mean you did not know the words used, by others, to describe it.

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 ? :whistle: :)
  • 0

#7 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9281 posts
  • Version:Unknown

Posted 07 October 2010 - 09:28 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.

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.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users