|
Author |
Topic: manual arrays (Read 310 times) |
|
minh
|
manual arrays
« on: Jun 28th, 2004, 7:31pm » |
|
how do you manually enter in values into an attay? like myArray = new (1,2,3,4,5,6); or myArray = [1,2,3,4,5,6]; both this methods give me errors. thanks.
|
|
|
|
toxi_ Guest
|
Re: manual arrays
« Reply #1 on: Jun 28th, 2004, 8:04pm » |
|
firstly, you'll need to specify the data type to be used for the array. then to create an array of preset values use the curly brackets ("{") instead of the squared ones ("[")... Code:int[] myArray = { 1,2,3,4,5 }; |
|
|
|
|
|
narain
|
Re: manual arrays
« Reply #2 on: Jul 2nd, 2004, 5:08pm » |
|
Also note: This will only work the first time ... i.e. at the time you're defining the array. So int[] myArray = {1,2,3}; will work, but this won't: Code:int[] myArray = {1,2,4}; // this is fine myArray = {1,2,3}; // can't do this anymore |
|
|
|
|
|
Sjeiti
|
Re: manual arrays
« Reply #3 on: Jul 5th, 2004, 9:13am » |
|
then again, this does work: int[] myArray; void setup() { myArray = new int[] {1,2,3}; }
|
http://www.sjeiti.com/
|
|
|
narain
|
Re: manual arrays
« Reply #4 on: Jul 5th, 2004, 6:10pm » |
|
Oh yes... I always forget about that little bit of syntax. Thanks for the correction.
|
|
|
|
|