Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Bushy
18
Years of Service
User Offline
Joined: 16th May 2006
Location:
Posted: 16th May 2006 22:09
I have looked everywhere to try and understand these three things but I just cannot get my head around them. I would be very grateful to anyone who can answer these three questions for me.

1)What arrays are?
2)What the purpose of them is?
3)How to use them?
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 16th May 2006 23:57
Arrays are slots for holding information in a long line.

Dim LottoNumber(6)

LottoNumber(1) = 3
LottoNumber(2) = 19
LottoNumber(3) = 21
LottoNumber(4) = 35
LottoNumber(5) = 42
LottoNumber(6) = 49

For n = 1 to 6
Print LottoNumber(n);
Print " ";
next n

Wait key

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th May 2006 00:00 Edited at: 17th May 2006 00:00
[EDIT] See what a phone call in the middle of surfing does!

Simple example...cards, 52 of them infact...

Dim Card(52) as string
Card(1) = "Ace of Spades"
Card(2) = "2 of Spades"
`... and so on



Now, you can print any card by referencing it's array element...

print card(19)

results in

6 of Clubs

They become more useful when you store game data, like the health of your 20 enemies, or the speed of your 6 vehicles. You can change the values at will, just like any other variable.

The big advantage of arrays, is doing something to every element...

For n = 1 to 20
DEC EnemyHealth(n), 1
Next n


which is far faster than using individual variables...

DEC EnemyHealth1, 1
DEC EnemyHealth2, 1
DEC EnemyHealth3, 1
DEC EnemyHealth4, 1
...




Programmer of Power
19
Years of Service
User Offline
Joined: 22nd Aug 2005
Location: Home
Posted: 17th May 2006 03:56
1. I had a lot of problems understanding arrays when I first started programming. It's like you have a box with different sections of it. Each section is part of th big box, so it has the same name, but each part has a different thing in it. You could have your name in one part and your friends name in another, but they're both in the same box under the same name.

2. Arrays are used to store lots of different information all in one variable. You could have all the cards in the deck, or the most recent lottery numbers, or previous scores in a high score list. The possibilities are endless!

3. How to use them..... Well first you create them:

This creates an array called intArray that contains 5 items. Yes, 5. 0, 1, 2, 3, 4.

To assign something to the array.

This puts the number 32 in the third part of the array.
Then you can access it at anytime by using any kind of syntax

Anyway. Hope I could help!

"I will work harder... if you ask me enough times... or give me enough coffee"
Bushy
18
Years of Service
User Offline
Joined: 16th May 2006
Location:
Posted: 17th May 2006 13:43
Thanks for all your help. I now know how to create arrays and I think I've nailed how to assign stuff to the array but using an array is still a bit hazy to me, could someone please expand on this for me. I get the impression that arrays are a major part of programming and I want to understand them completely.
Sorry for being so new to all this programming stuff.
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 17th May 2006 15:59
The way I use arrays most of the time, is in a 'FOR' loop.

Say I have an array of enemies' X positions (and each baddie is numbered from 100 to 105, and I want to make them all move at the same time....


Now, if I'd had to do that for 5 individual baddies, then I'd get really annoyed at having to repeat all that code. If it was for 500 baddies, then I'd go mad. Using arrays, means I can loop through the entire array (using FOR) and do everything in the loop once to each member of the array.

Admittedly, I seldom use normal arrays, I use User Defined Types - they're like arrays, but with the ability to put much more information into them.
Bushy
18
Years of Service
User Offline
Joined: 16th May 2006
Location:
Posted: 17th May 2006 17:08
So by using an array you can control many different variables with a lot less code

Quote: "Admittedly, I seldom use normal arrays, I use User Defined Types - they're like arrays, but with the ability to put much more information into them. "


What are User Defined Types?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th May 2006 17:38 Edited at: 17th May 2006 17:38
Two tutorials, the first will teach you all about arrays and also about Types. Putting the 2 together gives you huge potential.

http://www.thegamecreators.com/data/newsletter/newsletter_issue_28.html#9

The second one expands on the same idea, but takes the concept to the next level

http://www.thegamecreators.com/data/newsletter/newsletter_issue_29.html#9

Sorry, but you can't make a clickable link when there is a "#" in the address



Programmer of Power
19
Years of Service
User Offline
Joined: 22nd Aug 2005
Location: Home
Posted: 18th May 2006 00:02
User defined types are sort of like arrays but they can store multiple types of information in them.

for example, lets say you had a character in an RPG with health, a name, statistics, items.. the list goes on and on. Anyway you can hold all of these in a user defined type under 1 name like PlayerInfo.

"I will work harder... if you ask me enough times... or give me enough coffee"
Bushy
18
Years of Service
User Offline
Joined: 16th May 2006
Location:
Posted: 18th May 2006 20:16
Thanks for all your help. Much appreciated.

Login to post a reply

Server time is: 2024-11-26 19:57:07
Your offset time is: 2024-11-26 19:57:07