|
Author
|
|
Thread
|
|
|
|
|
|
02-11-2003 02:41
Posted by:
Ashlin Aronin

|
I don't really understand arrays. I read the section on them in the Programming tutorial, but that didn't help. Can someone give me some more info on how to use them?
Thanks in advance,
Ashlin
|
|
02-11-2003 03:56
Posted by:
Machi

|
Think of an array as something like an egg carton. The carton is a single "thing" but it has a number of spaces inside it for separate eggs to be placed into.
In a similar way, an array is declared in a way that indicates how many separate values can be placed into it, and each space is indicated by an index number or variable.
For example, the following is an array ...
global int eggCarton[12]
... which can hold 12 different numbers in its little spaces
global int eggCarton[6]
... would hold six different numbers, which are referenced 0 to 5
global int thisValue
global int eggCarton
thisValue = 15
eggCarton[0] = thisValue
eggCarton[1] = 654
... would place an integer value of 15 into the first "space" in eggCarton and a value of 654 into the second space
global int thatValue
thatValue = eggCarton[1]
... would make thatValue equal to 654 - that's pretty much it, but of course you can use an integer variable as the index instead of just a straight numeral. So that the following ...
thisValue = 1
thatValue = eggCarton[thisValue]
... would also make thatValue equal to 654 (given the previous coding of course)
I hope that this helps
|
|
02-11-2003 22:59
Posted by:
someone
Location:
Quebec ( Canada )

|
Yeah, it would do the same thing if you used:
> int bonus1,bonus2,bonus3,bonus4
instead of
> int bonus[4]
but the array is shorter to declare, you don't need to know how many items there will be when you write the game:
> int bonus [ random ( 5,10) ]
and you can use a variable instead of the index:
> for n=0 to bonusNumber
> if bonus[n]=1 then bGot=bGot+1
> next n
>
> print "You got"
> print bGot
> print " bonuses. There was a maximum of"
> print bonusNumber
this code would be used to give a score at the end of a level, and can be modified to pass all map objects, for example.
|
|
02-12-2003 11:53
Posted by:
mark_667
Location:
England

|
Can an array be used to sore text as well as numbers? If so, is it just individual letters or entire words and phrases?
|
|
02-12-2003 13:01
Posted by:
John Treece-Birch

|
String Arrays
An array can also be made out of strings.
string array[100]
In which case, each element of the array can hold a word, phrase or sentence.
array[0]="Hello"
array[1]="world"
Thanks,
John
|
|
All times are GMT
|
|
|
|
|