Cannot convert Float[] to Float?
Monkey Forums/Monkey Programming/Cannot convert Float[] to Float?
| ||
I created an array of float values. I'd like to access one of those float values by index and add or subtract it from another float value. However, if I index that particular value, I get a "cannot convert Float[] to Float error". Apparently the Monkey array system, rather than storing a Float in a n Array of Type float, makes each float value an array of its own? How do I get around this and/or convert from Float[] to Float? Do I really need to make an ArrayList instead, which stores an object with a float in it, then reference the object by index, then extract the float from that instance? That seems pretty convoluted for what is essentially accessing a list of numbers... I'm sure I'm missing something, but after many hours of looking through docs, searching, reading the forum, looking at various unrelated source code, I'm at a loss on something that seems as though it should be quite simple. |
| ||
works fine here:Function Main:Int() Local myfloat:Float[] = [1.0,1.1,1.2] Print myfloat[1]+myfloat[2] End Function you need to provide an example to see what you are doing wrong. . |
| ||
Could you provide some code? This works for me, but maybe I didn't get your question: [monkeycode] Strict Function Main:Int() Local arr:Float[10] For Local i:Int = 0 Until 10 arr[i] = i+1.2 Local number:Float = 10 - arr[i] Print number Next Return 0 End [/monkeycode] |
| ||
Actually I was just being stupid, indexing one array of floats, but not the other. The code helped though. Hours over something so silly....argh... Thank you. :D |