Notifications
Clear all

[Closed] "global space" in scene for scripts

Hi there,

I have a bit of a strange question:
Is there a place in a 3d studio max scene where I can put scripts (functions, structs, constants,…) that can be accessed from other parts in the scene, like expressions for example?

The thing is: if I put functions inside an script expression it runs those functions a way too often and everything gets really slow.

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

Posts: 0

there is an old school trick. you can add a CA to the scripted controller, and use any function, structure, data, etc. from it.

Maybe I’ve overseen something.

I am looking for a place that can be used to put in some functions/structs. Those functions/structs get initialized one time only. Other scripts (an object’s script expression for example) can call those functions/structs.

You can place the scripts defining those global structs/functions in <stdplugs\stdscripts>
This way they are initialized during Max’s startup even before Macroscripts are executed, hence you can use your structs/functions already in a macroscript.
There is a second folder <scripts\Startup> which’s content gets executed too during Max launch, but irritating enough this happens AFTER the macroscript folder content’s get executed. Thus you can’t use structs/functions defined in scripts sitting in the <scripts\Startup> folder inside macroscripts. Conclusion: if you want your structs/function really be globally available, place the according script in <stdplugs\stdscripts>

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

that’s how i usually do it. it’s the most native way for the max.

Thank you for your answer!

So the only option would be to put the functions inside those folders? I thought there might be a “scene script” or something saved with the max file itself.

1 Reply
(@spacefrog)
Joined: 11 months ago

Posts: 0

seems i missed the “scene” part in your “global to scene” description…

You can keep variables into a scene using persistent variables :
http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-2739C3A0-16DB-4871-9F69-DCEC0862A186.htm,topicNumber=d30e138545

However this is not recommended in MAXSript help, and as it recommends i’d tell you to use custom attributes, for instance a dummy object that will hold all your variables.

Thank you all!
I will try to make it with custom attributes, at least for the variables. Would be nice if this works with functions as well.

I find the best way to store information is with setAppData and the rootNode

setAppData rootNode 1234567 “”

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

just a notice… only this channel can be used to store a data!

Good morning everybody!

Thank you for your suggestions. I think I will try the CA/scripted controller solution.

denisT, could you tell me where I have to put the functions?


(
	the_weaponData = attributes weaponData attribID:#(0x56e45049, 0x628574e9)
	(
		function funk=
		(
			print "funky"
		)
		parameters main
		(
			
		)
	)
	
	custAttributes.add $ the_weaponData

	$.weaponData.funk()
)

I don’t get access to the function.

Damn.
It works exactly as expected!! There seemed to be an “old” custom attribute that didn’t have the function inside…

Thank you!!!

Page 1 / 2