[Closed] help me understand this undefined error
This is a part of a script I am working on. The BSLMat array is much longer but cut it down to make it easier to follow. First time I run the script it will always do:
>> MAXScript Rollout Handler Exception:
– Unknown property: “blendState” in undefined <<
Second time it will do as I want. I have had similar errors before when functions isn’t declared in the right order and such (scope). But this just doesn’t make sense… Does anyone know what is weird? And if there is a better way to do it I’m all up to it! Am new to Maxscript and am trying to learn.
Thanks in advance!
fn standardToBSLFx obj =
(
local BSLMat=#(
#(
“AlphaParam”
),
#(
“blendState”
)
)
–get old material and make a new BSLFX
oldMat=obj.material
newMat = BSLightingFX()
for i = 1 to BSLMat[1].count do
(
execute(“newMat.”+BSLMat[1][i]+”=”+“oldMat.”+BSLMat[2][i])
)
obj.material=newMat
)
–convert just selected objects materials
fn convertSel=(
objs=(Selection as array)
for obj in objs do (
if (classof obj.material == Standardmaterial) then (
obj.material=standardToBSLFx(obj)
)
)
)
rollout RL_UiddsSel1 “Convert Imported Materials” width:160 height:100
(
button btn_cnvS “Convert Selection” pos:[16,45] width:130 height:21
on btn_cnvS pressed do
(
convertSel()
)
)
FirstDialogs = newRolloutFloater “FO4” 180 630
addrollout RL_UiddsSel1 FirstDialogs
Your error is on line 13:
newMat = BSLightingFX()
Ther is no BSLightingFX() function in the code.
execute("newMat."+BSLMat[1][i]+"="+"oldMat."+BSLMat[2][i])
You know, execute works in global scope, not local scope. 90% of the cases you think ‘I know, I’ll use execute’, think again. Use getProperty+setProperty instead here.
Ah, yes, that is a Beth material.
Interesting that execute don’t work in local scope. Will look into get/setProperty. Thanks!