Create rollouts inside functions or not

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2013
Create rollouts inside functions or not

Hi,

I'm trying to clean up a large collection of scripts, so that I can release them online. I'm not really a proper scripter (just faking it), and there are some things that have bothered me for some time:

Is it OK to create rollouts and floaters inside a function? For the past years I've done buildGUI() functions that does this. But when I try to update an old script to this method, I can't fetch slider and text fields from the rollouts any longer.

I've always had problems bringing values in and out of rollouts. For example, this script has a character height value in one rollout spinner, that other rollouts events need to fetch before running scripts. At the moment I use a global variable to push this value in and out of the spinner when it's changed or needed. Is this OK, or is there a better method?

Also related, I need to make certain buttons and elements disabled if a script component is missing. I'm thinking about using a global variable for this as well, and it will be checked each time the script is started. I keep reading that programmers should stay away from global variables, but very often my brain finds that to be the easiest solution
__________________
www.superrune.com
 
  01 January 2013
I'm just a "make it up as I go" scripter too. But I usually create functions as part of rollouts, rather than the other way around. I always define the rollout as global so when you start another instance of the dialog, you can auto shut the last instance of it down automatically.

And if I have more than 1 rollout (say within a rollout floater) and need to access functions or UI values within other rollouts, I can just call them via the global rollout name. (Which I make quite descriptive and verbose to avoid possible conflicts. This negates the need to define lots of global variables. Don't know if this will help you, but might give you something to think about.

Cheers,
Cg.
__________________
Not bad. For a hughman.
 
  01 January 2013
yes, you can create a rollout inside a function. what's after?
you can find some samples on this forum where i create rollout in function, or in structure...
 
  01 January 2013
Here's an quick example of rollouts created by functions inside a structure all the rollouts are visible to each other and only one global variable:
(
	clearListener()
	
	try (closeRolloutFloater ::rollTest.rollFloat) Catch()
	
	struct rollouts
	(
		public rollFloat, rollout1, rollout2, rollout3,
		
		fn createRollout1 =
		(
			local r = rollout roll1 "Rollout 1"
			(
				on roll1 open do
				(
					roll1.rollStruct = this
				)
				
				local rollStruct
				
				fn printCBs =
				(
					print rollStruct.rollout1.cb1.state
					print rollStruct.rollout2.cb2.state
					print rollStruct.rollout3.cb3.state
				)
				
				button b1 "Button 1"
				checkBox cb1
				
				on b1 pressed do printCBs()
			)
			r
		),
		
		fn createRollout2 =
		(
			local r = rollout roll2 "Rollout 2"
			(
				on roll2 open do
				(
					roll2.rollStruct = this
				)
				
				local rollStruct
				
				fn printCBs =
				(
					print rollStruct.rollout1.cb1.state
					print rollStruct.rollout2.cb2.state
					print rollStruct.rollout3.cb3.state
				)
				
				button b2 "Button 2"
				checkBox cb2
				
				on b2 pressed do printCBs()
			)
			r
		),
		
		fn createRollout3 =
		(
			local r = rollout roll3 "Rollout 3"
			(
				on roll3 open do
				(
					roll3.rollStruct = this
				)
				
				local rollStruct
				
				fn printCBs =
				(
					print rollStruct.rollout1.cb1.state
					print rollStruct.rollout2.cb2.state
					print rollStruct.rollout3.cb3.state
				)
				
				button b3 "Button 3"
				checkBox cb3
				
				on b3 pressed do printCBs()
			)
			r
		),
		
		fn createUI =
		(
			rollout1 = createRollout1()
			rollout2 = createRollout2()
			rollout3 = createRollout3()
			
			rollFloat = newRolloutFloater "Test Float" 100 250
			addRollout rollout1 rollFloat
			addRollout rollout2 rollFloat
			addRollout rollout3 rollFloat
		),
		
		start = createUI()
	)
	global rollTest = rollouts()
)
 
  01 January 2013
Cool! Didn't know about this. Might be useful in the future.
 
  01 January 2013
i've showed another techniques... for example : http://forums.cgsociety.org/showpos...830&postcount=7
 
  01 January 2013
These examples are great - thanks for the help! I will see if I can do this on my scripts as well, it is a lot cleaner than what I have been doing.
__________________
www.superrune.com
 
  02 February 2013
This was a lot harder to get my head around than I thought. It's radically different from what I have at the moment, and a huge job to try and change. My current version does not work at all. Dan, your sample is the easiest to imitate, but there are a couple of things I don't understand:

What does this line do? :
roll1.rollStruct = this

I don't see the "this" keyword anywhere else, so what does it change?

And the same with this line:
local rollStruct

It's a variable declaration, I reckon. But I don't see this variable given any content anywhere! Still it's used to hold the rollouts, how did that happen?

And also, I see the function "printCBs" being declared within each rollout but with essentially the same content. Seems like redundant code? Could this be more efficient?

My floater changes size if rollouts are closed and opened, but I can't get a reference to the floater itself inside any of the rollout functions. Would this be rollStruct? I would assume that to be rollFloat, but I reckon that's local to the createUI() function?
__________________
www.superrune.com
 
  02 February 2013
Check the Maxscript help for 'This' Local Variable in Scripted Controllers. In this case I believe that 'this' is a wrapper for the rollout (where [x] = the rollout number), which in turn is assigned to roll[x].rollStruct. So it should be something like this:

r = rollout roll[x] "Rollout [x]"
roll[x].rollStruct = r
rollStruct = roll[x].rollStruct
Result: rollStruct == r, in the context of r

So in in reality r, roll[x].rollStruct, and rollStruct all refer to the rollout created on that function, but allow the rollout to self reference.

Or I could be completely wrong. Dan or Denis am I close to understanding this correctly?
-Eric
__________________
"The Evil Monkey hiding in your closet."
 
  02 February 2013
This is used within scripted plugins to refer to the current instance so you are correct, but so far as I know, it doesn't work within a plain rollout, only one created within the context of for example a modifier or material.
__________________
http://blog.senorfreebie.com
My own self-interested promotion of technical ramblings and portfolio updates.
 
  02 February 2013
Originally Posted by PiXeL_MoNKeY: Denis am I close to understanding this correctly?

in this case this is the structure (instance of this structure) where the rollout was defined.
look at this sample:

struct test
(
	param = 0,
	name = "Button",
	rolloutname = "Rollout",
	rol = 
	(
		rollout rol this.rolloutname
		(
			button bt this.name
			on rol open do format ">> % %\n" this this.param 
		)
	),
	on create do createdialog rol
)
test param:2

using this we can get access to all structure's properties, and can use them for the rollout creation.
 
  02 February 2013
the same meaning of this is for scripted plugins (all kind), custom attributes, and structures...
also you can use this in scripted controller expression, which means this controller itself.
 
  02 February 2013
Thanks to this thread (and the wonderful generosity of the members of this forum with their knowledge and time) I'm currently re-forming my whole script system into a new structure based one. I have the main structure, inside which there are all the various rollouts as well as an additional structure which has all of the functions that are used amongst the various rollouts. Of course, they can all talk to each other's UI elements and any functions I were to define within each rollout anyway, but this way it's a bit neater.

It's taken some time getting my head around it, but it's nice now that it is! Since I'm doing such a significant rejig, I'm also taking the time to have multiple rollouts within a single dialog, which makes the UI a bit nicer, too.
__________________

 
  08 August 2013
Originally Posted by denisT: in this case this is the structure (instance of this structure) where the rollout was defined.
look at this sample:

struct test
(
	param = 0,
	name = "Button",
	rolloutname = "Rollout",
	rol = 
	(
		rollout rol this.rolloutname
		(
			button bt this.name
			on rol open do format ">> % %\n" this this.param 
		)
	),
	on create do createdialog rol
)
test param:2

using this we can get access to all structure's properties, and can use them for the rollout creation.


Maybe I am missing something, but I get this when I run that sample:
-- Error occurred in anonymous codeblock; filename: C:\Users\ahosking\Dropbox\3DS Max Development\UI\; position: 143; line: 10 
-- Syntax error: at ., expected name 
-- In line: button bt this.n

Last edited by AlexanderH : 08 August 2013 at 05:43 PM. Reason: Legibility
 
  08 August 2013
Originally Posted by AlexanderH: Maybe I am missing something, but I get this when I run that sample:
-- Error occurred in anonymous codeblock; filename: C:\Users\ahosking\Dropbox\3DS Max Development\UI\; position: 143; line: 10 
-- Syntax error: at ., expected name 
-- In line: button bt this.n



Turns out that a simple definition change in Max 2011 is required to fix this.
button bt this.name

becomes
button bt text:this.name
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:43 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.