Notifications
Clear all

[Closed] Array Question

I have a file with a setup i am not sure of the best way to handle.
I have a list of names as a string variable in one section.
I am able to read the names and print them out in that same loop but how would I add these names into an array. it always complains its not a float value.

my loop is like
for i = 1 to number_of_names Do (
TexName = readstring f
print TexName
)

and in another section i have a setup of
for i = 1 to modelnumber do (
TextureType = readstring f
texturenumber = readlong f
print TextureType
print texturenumber
)
the output of the second print is like
diffuse
1
normal
2
so it would set the diffuse to the first texture in the list and the normal map to the second texture in the list.
I just can’t figure out how to get this to work.
Thanks so much in advance

8 Replies

Is this what you’re looking for?


(
   local texture_names = #() --initialize names array
   for i = 1 to number_of_names do (
      append texture_names (readstring f)  --append name read to array
   )
   print texture_names
)

 JHN

And offcourse there’s always a smart@ss:


local names = for i = 1 to number_of_names collect readstring f
print names

-Johan

Yep, it might be a bit faster as well.
Of course it’ll only work if you just have the names, and don’t have to read anything else in between.

Thanks both of you for your replies that worked great I ended up doing it like this

texture_names = #() --initialize names array
  for i = 1 to TexNum Do (
  texture_name = readstring f
  append texture_names texture_name  --append name read to array	
  skipbytes = 0x10 - texture_name.count - 1	
  fseek f skipbytes #seek_cur
  )
  print texture_names

in my second array i have a string followed by 3 variables
so it would look like this

texture_details = #() --initialize names array
  for i = 1 to MaterialNumber Do (
  Material_property = readstring f
  skipbytes = 0x10 - Material_property.count - 1    
  fseek f skipbytes #seek_cur
 var1 = readlong f
 var2 =readlong f
 var3 = readlong f
 append texture_details Material_property var1 var2 var3   --append name read to array   
  )
 now based on this i want to do this
 if Material_property == "Diffuse"
 set the objects material to the variable properties
 so how would i call that so it looks in the array till it finds that name and then applies those values that are in that section of the array?
 
 Does my question make sense?
 i know how to apply the material i just don't know the best way to read the array to get the information.

I’m not sure if this is what you are after, but you could consider using an associative array. If you have unique identifiers, this will work nicely:


(
  local mat_properties = #()
  for i = 1 to MaterialNumber do
  (
     local mat_name = readstring f
     local skipbytes = 0x10 - mat_name.count - 1 --I'm a bit confused why you'd need this line?
     fseek f skipbytes #seek_cur
     local var_array = #()
     append var_array (readlong f)
     append var_array (readlong f) -- and so on; maybe loop this.
     mat_properties[mat_name] = var_array
  )
)

Then you could use this array in much the same way as when assigning values:


somematerial.diffuse.aproperty = mat_properties["diffuse"][1]

Or something like that. If all your properties are the same, you could also consider making a struct instead of the var_array, that’d make things a bit neater.

ok I think i understand how you are appending to the array here but i am not quite sure of this line
the skip bytes is because each texture name is 0x10 and i need to skip that many bytes of 00’s that trail the string length
somematerial.diffuse.aproperty = mat_properties[“diffuse”][1]what I have going is something like this
msh.material = meditMaterials[i]
meditMaterials[i].name = MeshName[i]
meditMaterials[i].diffuseMap = Bitmaptexture texture_names:[var1]
how would i do this
so it knows that it only applies the line
meditMaterials[i].diffuseMap = Bitmaptexture texture_names:[var1]
when the mat_properties string is = “diffusetex”

This is what i am trying to read.


mat_properties = #()
for i = 1 to MatNumber Do (
matoff1 = ReadBElong f + 8
MatLoopPos = ftell f
fseek f matoff1 #seek_set	
MatIDName = readstring f
append mat_properties MatIDName  --append name read to array
skipbytes = 0x10 - MatIDName.count - 1
fseek f skipbytes #seek_cur
ushort1 = ReadBEword f
ushort2 = ReadBEword f
matid = (ReadBElong f)
fseek f MatLoopPos #seek_set
)
print mat_properties

this is the output
“g_f4MatAmbCol”
“g_f4MatDifCol”
“g_f4SpecularCol”
“g_fSpecularLev”
“g_iSpecularPow”
“g_fHDRAlpha”
“g_bUseRefCube”
“g_bUseRefRegMap”
“g_bReflectAdd”
“g_fReflectAlpha”
“texDiffuse”
“texSpecularMap”
“texSphRefction”
“texCubeRefction”
“texRefctionReg”
“g_f4MatAmbCol”
“g_f4MatDifCol”
“g_f4SpecularCol”
“g_fSpecularLev”
“g_iSpecularPow”
“g_fHDRAlpha”
“texDiffuse”
“texSpecularMap”
“g_f4MatAmbCol”
“g_f4MatDifCol”
“g_f4SpecularCol”
“g_fSpecularLev”
“g_iSpecularPow”
“g_fHDRAlpha”
“texDiffuse”
“texSpecularMap”
“g_f4MatAmbCol”
“g_f4MatDifCol”
“g_f4SpecularCol”
“g_fSpecularLev”
“g_iSpecularPow”
“g_fHDRAlpha”
“texDiffuse”
“texSpecularMap”

i want to do an if statement that if mat_properties = texDiffuse get matid
that is the texture number from the first loop

I got it I created a new array based on those 2 arrays and read the values from it.