Notifications
Clear all

[Closed] Custom Attributes scope

 eks

Hello,

I have a struct with a variable and a couple of functions. On it’s creation, I make a dummy with a custom attribute. But everything inside this custom attribute cannot access the local stuff from the struct. Here’s an example:

struct limb
(
	skeleton,
	fn updateSkeleton val =
	(
		for lBone in skeleton do
		(
			print "updating fkik weights"
		)
	),
	
	on create do
	(
		ctrlNode = dummy boxsize:[0.2, 0.2, 0.2] 
		
		--customattribute 
		limbDataCA = attributes limbData
		(
			parameters main rollout:params
			(
				fkik type:#float ui:fkikSpin default:100
			)
				 
			rollout params "limbData"
			(
				spinner fkikSpin "FKIK" type:#float
				
				on fkikSpin changed val do
				(
					updateSkeleton val -- <----- the crucial point is here
				)
			)
		)
		custAttributes.add ctrlNode limbDataCA
	)
)

arm = limb skeleton:armBones

updateSkeleton doesn’t seem to exist for limbDataCA. If I place that for loop from updateSkeleton inside the attribute, it won’t find the skeleton variable. The only way for it to find updateSkeleton would be to place it as a global, but I can’t do that because this struct is going to be used multiple times. The same goes with limbDataCA, I can’t make it global because it’s supposed to be an attribute of that specific struct

I haven’t used custom attributes much yet, am I doing something wrong? Or there really is no other way?

*edit: could it be the rollout scope the problem instead of the parameter…?

2 Replies
 PEN

The CA Def is not in the scope of the struct or vise versa and it is not because of anything that you have done.

What you need to do is call the struct from the def via an instance of the struct.

Limb.updateskeleton()

Hope that helps.

 eks

Yes! It helps! It was exactly the problem!

Thanks a lot!!