PDA

View Full Version : problem reading position values from txt file


upflight
06-16-2005, 07:06 PM
Hi.
I'm creating a script to animate an object acording to position coordenates stored inside a txt file. The txt file has in each line a numeric value. When trying to run the code below i'm getting an error "-- Unable to convert: "49" to type: Float" as soon as it reads the first value.
Can anyone help me figure out why??? f = openfile "C:\Documents and Settings\Light\Desktop\projecto3D\locIberia.txt"
t=1
j=5
while not EOF f do
(
val = readline f
x = val
val = readline f
y = val
val = readline f
z = val
ponto = point3 x y z
at time t animate on $Carro.position=ponto
t=t+j
)
close f

Bobo
06-16-2005, 10:44 PM
Hi.
I'm creating a script to animate an object acording to position coordenates stored inside a txt file. The txt file has in each line a numeric value. When trying to run the code below i'm getting an error "-- Unable to convert: "49" to type: Float" as soon as it reads the first value.
Can anyone help me figure out why??? f = openfile "C:\Documents and Settings\Light\Desktop\projecto3D\locIberia.txt"
t=1
j=5
while not EOF f do
(
val = readline f
x = val
val = readline f
y = val
val = readline f
z = val
ponto = point3 x y z
at time t animate on $Carro.position=ponto
t=t+j
)
close f

Sure.

readline reads a string. You have to turn that string into a float value.
There are multiple ways to do this.

The best is to use readValue instead of readLine.
readValue reads a string delimited by space, coma or EOL and turns it into a MAXScript value internally.

Another way would be to use

x = val as Float

or

x = execute val

In general, you don't need all these intermediate variables. Also, either use / slashes or double-backslashes \\, never single backslashes in file names.

f = openfile "C:\\Documents and Settings\\Light\\Desktop\\projecto3D\\locIberia.txt"
t=1
j=5
while not EOF f do
(
at time t animate on $Carro.position = point3 (readValue f) (readValue f) (readValue f)
t=t+j
)
close f

erilaz
06-17-2005, 01:09 AM
I love execute so much! Converting text arrays as never been so easy! :D

upflight
06-17-2005, 04:42 PM
thx a million for the help :D

CGTalk Moderation
06-17-2005, 04:42 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.