Reading from file (2 problems)...

BlitzMax Forums/BlitzMax Beginners Area/Reading from file (2 problems)...

Ryan Burnside(Posted 2007) [#1]
Hello again

I'm midway through writing a conversion program that takes an Anim8or file and converts it to an Open GL list. Currently I'm having two problems,

1. I need tot vertexes to be stored as they are written in the text file. I really have no choice I have to convert the strings into floating values. The accuracy is terrible some of them have up to 3 tenths off. I've heard that bmax can't handle converting a string to float even if the float string is well within the length of a float.

Do I really need to iterate through values in the string and add the proper values to a base float?

Aka string ="35.678"

30.0
5.0
.600
.07
+ .008
--------------
35.678

My next question I save all vertexes to a two dimensional array. I don't know how big the global array has to be when i start the program. Only after the user selects and reads a file do I know how big to make the array. The array is three indicies wide (x,y,z) and I don't know height because the array point numbers vary.


Gabriel(Posted 2007) [#2]
I've heard that bmax can't handle converting a string to float even if the float string is well within the length of a float.

Don't know where you heard that. I convert back and forth between floats and strings all the time, and it works fine.

I wasn't sure what part of the second question was a question so I just stuck to the first one.


GfK(Posted 2007) [#3]
I think he's asking "How do you read data into an array when you don't know how big the array is going to be".

That being the case, I'd suggest using a TList. You can then use TList.ValueAtIndex() to operate the TList in the same way you'd use an array.


Brucey(Posted 2007) [#4]
In the IDE, goto Help -> Language -> Strings.

In the list of methods is ToFloat()

which you use something like :
Local s:String = "6.45"

Local f:Float = s.ToFloat()




Brucey(Posted 2007) [#5]
The array is three indicies wide (x,y,z)

Create yourself a type :
Type TVertex
    x:Float
    y:Float
    x:Float
End Type

and as Gfk suggests, store them in a List. You can always convert this to an Array when you are finished building it.


Ryan Burnside(Posted 2007) [#6]
Ok I didn't know you can directly access elements of a list without using a for loop and iterator. Solved. :)


When I read in numbers from files they get messed when read as floats...

ex
-14.532

becomes

-14.5299997

I've had worse results too. The number -14.532 can be represented by a float can't it?


Gabriel(Posted 2007) [#7]
I don't know why you'd get that. I get -14.5319996 which is pretty decent.

I also don't get the use of String.ToFloat(). It must just be me because a lot of people seem to use it, but I always just preferred :

Local s:String= "6.45"
Local f:Float=Float(s)



Ryan Burnside(Posted 2007) [#8]
It would appear that I had an issue with the space tokens in my files. All correct now. Thanks for all the help.

A new problem arises:

I have saved all my point objects to a handy dandy array but point_list.valueatindex(index:int) returns an Object not a point...


I get the following error:

"unable to convert 'Object' to 'point' "


Perturbatio(Posted 2007) [#9]
try casting it.
point = TPoint(point_list.valueatindex(index:int))



Ryan Burnside(Posted 2007) [#10]
Ahhh that seems to work! It's odd you have to cast the objects.


ziggy(Posted 2007) [#11]
It is very common on non COM based objects. If you're a Visual Basic 6 programer, it can seem strange to you, but it makes the language faster, becouse the program doesn't have to deal with interfaces at runtime.In fact, not doing this would force the language to provide a late binding mechanism, and this always speed down performance and increases programs memory usage.