|
Author |
Topic: vector -> array? (Read 328 times) |
|
nay
|
vector -> array?
« on: Sep 14th, 2004, 9:02pm » |
|
hi i just started playing around with the osc library to recieve stuff. there is a built in function in the library called mic.getOscData() which will return for example [0,0] i tried to access it like an array but that didn't work and neither did assigning the entire output to an array. it says that it can't convert it from vector to int[] does anyone know how to get around this? i'm afraid i don't know what vector means in this context
|
|
|
|
nay
|
Re: vector -> array?
« Reply #1 on: Sep 14th, 2004, 9:16pm » |
|
whoops - posted too soon even though i still don't understand the diff tween vectors and arrays, with a bit of cut and paste i managed to get it to work with: Vector v = mic.getOscData(); var1 = ((Number) v.elementAt(0)).intValue(); var2 = ((Number) v.elementAt(1)).intValue();
|
|
|
|
Robin
|
Re: vector -> array?
« Reply #2 on: Sep 15th, 2004, 6:46am » |
|
Hi nay, My knowledge is extremely limited as i am learning too, but i figure i'll have a shot at it anyway afaik, vectors are like arrays but cannot hold primitive data types (ints, chars etc) -- instead, they can only hold objects (such as Strings, Integers). If you wanted to store ints or chars in a vector, you would need to use what i think is called a wrapper class, which converts a value of a primitive type to an equivalent value of a class type. Code:int n = 50; // primitive Integer m = new Integer(50); // wrapper class |
| I think (?) using vectors allows you to do some powerful things that might be otherwise very difficult with arrays. Infact, i'd be very interested in seeing examples or understanding why one would choose to use a vector over an array.
|
« Last Edit: Sep 15th, 2004, 6:47am by Robin » |
|
|
|
|
nay
|
Re: vector -> array?
« Reply #3 on: Sep 15th, 2004, 3:21pm » |
|
thanks robin - makes a bit more sense the osc protocol that this code and library is for can take all data types from the other end to send to p55, so i guess it converts them all into the same format (needs to be the most complex possibilty so more complex than ints, hence a vector as opposed to an array?) and sends that across? wouldn't mind seeing some examples either, but at least it works!
|
|
|
|
|