Home Technical Talk

[Maxscript] discard array items doesn't work fine

polycounter lvl 7
Offline / Send Message
EspiSensei polycounter lvl 7
Hi everyone!

I'm trying to develop a tool which  has 2 arrays (Prueba1 is the main array  and prueba2 contains the words that musn´t appear).  

First erase the " * " character and later through the "FindString" function check if it was a string correct or not. But i have an exception which i don't see right now, this exception is with Prueba 1 ("prueba_emissive_11").

Can you help me with this stupid bug ? :S  jajajaja  thanks! 


prueba1 = #(
"prueba111",
"LA_emissive_prueba1",
"prueba_emissive_11",
"prueba_caliper_garage",
"prueba22",
"car_interior_garage",
"Car_shadow"
)


prueba2 = #(
"*emissive*",
"*_caliper_garage",
"interior_garage",
"*shadow*"
)
fn getNamesOfMeshesThatRequireUV2 = (
local meshesThatRequireUV2 = prueba1 
 
for n in prueba2 do (
local exceptionName = substituteString n "*" "" 
for m in prueba1 do (
local TheName = m
if findstring theName exceptionName != undefined then (
deleteItem meshesThatRequireUV2 (findItem meshesThatRequireUV2 theName)
)
)
)
messagebox (meshesThatRequireUV2 as string)
)


getNamesOfMeshesThatRequireUV2()

Replies

  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    This is why side-effects make stuff hard :smile: You're iterating over an array and modifying that array at the same time. Either collect a new array as you go instead of deleting from you working set, or iterate backwards (i.e. for i = prueba1.count to 1 by -1 do (local TheName = prueba1[i] ...).
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Thank you Swordslayer! i try it! Later i will tell you new!
  • EspiSensei
    Offline / Send Message
    EspiSensei polycounter lvl 7
    Swordslayer, i got it!

    thanks for all!1 finally I've develop the function this and works! :smile:

    fn getNamesOfMeshesThatRequireUV2 = (
    Local meshesThatRequireUV2 = #()
    for i =1 to prueba1.count do (
    Local theName = prueba1[i]
    Local checked = True
    for j=1 to prueba2.count do (
    Local exceptionName = substituteString prueba2[j] "*" "" 
    Local result = findString theName exceptionName as string 
    if findString theName exceptionName != undefined then (
    checked = false
    )
    print (" prueba1 :  "+ (theName) +"   exception!!:  " +(prueba2[j] as string) + "    resultadooo:   "+ result + " ----CHECKED-----   "+ (checked as string))
    )
    if checked == true then (
    append meshesThatRequireUV2 theName
    )
    )
    messagebox (meshesThatRequireUV2 as string)
    )


Sign In or Register to comment.