Notifications
Clear all

[Closed] Scope/Visibility Confusion

I’m not sure how I’ve gotten this far without a firm grasp on scope and visibility in mxs, but here’s my problem.

I’ve got a floating rollout that has a couple progressbar controls on it. I’ve used include statements at the top to get some rendering functions that the rollout will trigger, passing them arrays of various configuration settings. The progressbars on the rollout should get updated by the functions to reflect the progress of rendering and compositing. Of course – as I understand it – the progressbar update isn’t happening because, as far as the function is concerned, the rollout doesn’t exist (or maybe it’s just the rollout control it’s not seeing). Obviously, if I rerun my script, it then finds the control and updates it like I’d wanted. The help files are a bit fuzzy on uninitialized local declaration, as they’re using their rollouts wrapped in utility declarations, and in my case, I can’t define local variables at the top-level. So how would I go about exposing my included functions to my rollout and/or ui controls? TIA

5 Replies

Well, if I declare my rollout variable as an uninitialized global before my includes, it works, but is this the correct way to do it, i.e. is doing so going to cause headaches down the road?

1 Reply
(@bobo)
Joined: 10 months ago

Posts: 0

It does not have to be global unless you want it to be (rollouts used as Dialogs are usually declared as global to allow for later closing and easier access from other scripts). So you can either say

(--start local scope
 local yourRollout --pre-declare as local
 include "someFunctions.ms"  --include inserts the code here, so the functions become local
 include "someMoreFunctions.ms"
 
 rollout yourRollout "Bla" --the actual definition
 (
 
 )
 )--end local scope

or

(--start local scope
 global yourRollout --pre-declare as global
 include "someFunctions.ms"  --include inserts the code here, so the functions become local
 include "someMoreFunctions.ms"
 
 rollout yourRollout "Bla" --the actual definition
 (
 
 )
 )--end local scope

or as you did

--no local scope
 global yourRollout --pre-declare as globla
 include "someFunctions.ms"  --include inserts the code here, the functions become global
 include "someMoreFunctions.ms"
 
 rollout yourRollout "Bla" --the actual definition
 (
 
 )
 --no local scope

In all these cases, the functions will SEE the rollout because it was pre-declared either in their top scope or in the global scope. I would have used the second example because I want the rollout to be global for dialog creation, but the functions to remain local to my script…

You probably need to refer to it in the scope of the rollout name:

progressbar_name.value =100 would error but
rollout_name.progressbar_name.value =100 should work

I thought that was all that was required, but my function script already calls it as a property of the rollout. Here’s the two scripts as they function now:

Rollout (excerpt)

global plyRenderUtils
 include "c:/[NEW MAPS]/[SCRIPTS]/PlaylandFN/fnLoRender.ms"
 include "c:/[NEW MAPS]/[SCRIPTS]/PlaylandFN/fnStdRender.ms"
 include "c:/[NEW MAPS]/[SCRIPTS]/PlaylandFN/fnAORender.ms"
 include "c:/[NEW MAPS]/[SCRIPTS]/PlaylandFN/fnReplaceChar.ms"
 
 
 rollout plyRenderUtils ""
 (
 	label taskLabel "Task Complete" pos:[183,380] visible:false
 	progressBar taskComplete color:(color 200 200 200) pos:[11,395] visible:false
 	label compLabel "Job Complete" pos:[185,410] visible:false
 	progressBar compComplete color:(color 200 200 200) pos:[11,425] visible:false
 )

fnAORender.ms (excerpt)


 include "c:/[NEW MAPS]/[SCRIPTS]/PlaylandFN/fnBlendModes.ms"
 
 
 fn aORender renderArgs shaderArgs =
 (
 	outFile = (renderArgs[3] + getFilenameFile rendOutputFilename + ".tif")
 	
 	case shaderArgs[1] of
 	(
 		1:
 		(
 			renderers.current = RendererClass.classes[3]()	
 			rendMod = renderers.current
 			rendMod.filter = 0
 			rendMod.BoxFilterWidth = 1.0
 			rendMod.BoxFilterHeight = 1.0
 			rendMod.maximumSamples = 3
 			rendMod.minimumSamples = 1
 		)
 		2:
 		(
 			renderers.current = RendererClass.classes[1]()
 			$sun01.shadowGenerator = Area_Shadows()
 			shad = $sun01.shadowGenerator
 			shad.shadow_Mode = 2
 			shad.pass1 = 5
 			shad.pass2 = 7
 			shad.blur = 2.0
 			shad.shadow_width = 9.0
 			shad.shadow_length = 9.0
 			shad.jitter_amt = 1.2
 			
 			trackviewnodes.raytrace_engine_globals[2][1].value = 3
 			for i=1 to sceneMaterials.count do
 			(
 				if matchPattern sceneMaterials[i].name pattern:"[METAL]*" then
 				(
 					sceneMaterials[i].samplerUseGlobal = false
 					sceneMaterials[i].samplerEnable = true
 					sceneMaterials[i].sampler = 2
 					sceneMaterials[i].samplerQuality = 0.5
 					sceneMaterials[i].subSampleTextureOn = true
 				)
 			)
 		)
 	)
 	
 	plyRenderUtils.compComplete.value = 0
 	plyRenderUtils.taskComplete.value = 0
 )

Thanks for the explanation Bobo, parentheses have become such an autonomic syntax that I didn’t even consider their actual function.