Notifications
Clear all

[Closed] Animate object with data from array

I have been working on getting an object to move on the X axis with values read from a text file into an array and then applied to the X coordinate, but i am getting an error. below is the listener output:

#()
<File:c: emp est.txt>
– Error occurred in j loop; filename: C:\3dsMax\max scripts\read-delimited-string07.ms; position: 340; line: 15
– Frame:
– j: 1
– called in anonymous codeblock; filename: C:\3dsMax\max scripts\read-delimited-string07.ms; position: 340; line: 15
– Frame:
– str: “7”
– Unable to convert: “7” to type: Float
OK
OK

here is the data in the file being read:
7,1,2,3,45,6

and the script I’m cobbling together like a Frankenstein Monster:

path_array = #()
in_text = openfile “c:\ emp\ est.txt”
while not eof in_text do
(
str = readDelimitedString in_text “,”
if str != “
” then append path_array str
(
for i=1 to path_array.count do
messagebox path_array[i]
)
(
for j=1 to path_array.count do
move $Sphere001 [path_array[j],1,1]
)
)
close in_text

I’m looking for any info as to why i’m getting the errors and how to correct them. There is a scene with 1 sphere named Sphere001. The message box lines where to verify the data is being read correctly from the file and into the array, and I have not removed them yet.

Thank you in advance for any assistance.

2 Replies

I’ve not used that way of reading data from a file, but from what I know, when you are reading the data from the file it comes in as a string. You have to make it a float value to turn it from being text to a number you can use.

I don’t have max here, so I haven’t tested it. But this should solve that error.

if str != "
" then append path_array (str as float)

Cg.

Thank you for the post. The issue is resolved now.