Notifications
Clear all

[Closed] Structs and Rollouts within helpers

Hi,

Im getting a really weird error messeage and I was wondering if anyone could help shine some light on thats going wrong here.

It sounds a bit odd, but I have a struct within a helper script. Within the struct I have a function to show a rollout in a popup, and Im trying to link the values up, so users can change the properties of the struct through this popup dialog box.
When I creat the rollout, it reads in a value from the struct fine, but when updateing the struct, I get the error “–Runtime error: Struct member access requires instance: TestNum”

Heres the code im useing:


plugin Helper TestHelper
name:"Test" 
classID:#(0x2a879060, 0x1bec5084)
category:"Test" 
extends:dummy 
( 
Struct Test(
		TestNum = animationRange.start, 
		fn CreateRollouts = (		
			rollout trollout "Setting" width:460 height:917
			(
				GroupBox grp1 "Timeline Settings" pos:[5,10] width:435 height:93
				label lbl32 "Frame Start:" pos:[20,35] width:63 height:16	
				label lbl33 "Frame Stop:" pos:[21,54] width:63 height:16
				spinner Start "" pos:[85,34] width:111 height:16 range:[-1e+008,1e+008,TestNum] type:#integer scale:1 
				on Start changed v do(
					TestNum = v
				)
			)
			createdialog trollout
		),
	Private
		on create do(
			TestNum = animationRange.start
		)
	)
local T = Test()
	rollout ControlPanel "Open Rollout Test" width:162 height:50
	(
		button btn1 "Open Rollout" pos:[7,10] width:145 height:31
		on btn1 pressed  do(
			 T.CreateRollouts()
		)
	)
)

Cheers

Geoff

2 Replies

I’ve had the exact same thing happen to me!
I’m new at maxscript, so take my opinion with a grain of salt…
You declare TestNum in the struct, then try to access TestNum from a function in the struct without first declaring an instance of the TestNum for the function to use.
I did the same thing and ran into the same problem, plus I wasn’t sure of the proper way to get the function to “see” the variable, in your case ‘TestNum’. My workaround was to drop using a struct, and instead just enclose the variable and function in ( ) brackets. This is not the way to do it, but works in pinch. I’m not aware of the proper syntax to make this work the way you’ve written it… but I wanna know! Anyone?

 PEN

I don’t see why you are trying to do it that way in the first place. The problem that you are having is scope. You would have to have the struct instance global for it to work I think.

If you want a rollout to pop up when a user presses a button then just place the rollout in function and run that. If you need that rollout to then access the plugin instance that it was fired from you need to pass an instance of to the function then once the rollout is launched you then need to pass that instance of the plugin to a variable in the rollout so that it has a local reference to it. You could just make the instance global but that is messy and can cause other issues later.