Notifications
Clear all

[Closed] trouble with variable scope in scripted material

Max is telling me it can’t find “defaultColor”, etc. Where should I be putting these?


plugin material simpleMetal
	name: "CKD Metal"
	classID: #(0x34717846, 0x3aec1cb5)
	extends: VRayMtl replaceUI:true version:1
(
	global defaultColor = (color 8 8 8)
	global defaultReflect = (color 120 120 120)
	global defaultReflectGlossy = 0.76
	global defaultIOR = 2.0
	global defaultAnistropy = -0.5

	parameters main rollout:params
	(
		_color type:#color default:defaultColor ui:_color
		_reflect type:#color default:defaultReflect ui:_reflect
		_reflectGlossiness type:#float default:defaultReflectGlossy ui:_reflectGlossiness
		_ior type:#float default:defaultIOR ui:_ior
		_anistropy type:#float default:defaultAnistropy ui:_anistropy
		_roundCorners type:#boolean default:true ui:_roundCorners
		_roundCornerRadius type:#float default:0.005 ui:_roundCornerRadius
		
		on _color set val do delegate.diffuse = val
		on _reflect set val do delegate.reflection = val
		on _reflectGlossiness set val do delegate.reflection_glossiness = val
		on _ior set val do delegate.refraction_ior = val
		on _anistropy set val do delegate.anistropy = val
	)
	
	rollout params "Metal Parameters"
	(
		colorpicker _color "Color: "
		spinner _reflect "Reflection: "
		spinner _reflectGlossiness "Reflection Glossiness: "
		spinner _ior "IOR: "
		spinner _anistropy "Anistropy: "
	)
	
	on create do
	(
		delegate.diffuse = defaultColor
		delegate.reflection = defaultReflect
		delegate.reflection_glossiness = defaultReflectGlossy
		delegate.refraction_ior = defaultIOR
		delegate.anistropy = defaultAnistropy
	)
)

4 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

if you want to have “defaultColor”, etc. global just move them out of the plugin’s body.
but it seems like i’m missing something. you have to understand that your plugin makes originally animatable parameters not animatable. is it ok?

I just want to set the initial values – isnt that what im doing?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

that’s what i expected. as i see you want to hide most of original parameters by hiding oridinal UI. you add two new parameters.
don’t override original params. use autoPromoteDelegateProps set to on. using of on create event you can set any param to any value you want. probably the right way will be to read these values from this plugin config file without using any global.

as i told in this forum i’m not paranoid against of using globals. but try to name them anyhow special. the defaultColor as a name is too common.