Notifications
Clear all

[Closed] Persistent Struct Definitions

I often want to store data in structs but in order to have these persistent with the max files you have to declare the structs again at startup before you open the file to have these structs not returned undefined.

Is there a way to embed the declaration of the struct in the file as well?

4 Replies

The only way I see (and surely you have thought about it) is saving the struct definition as string and executing it at loading time.

you can do something like this:

attributes PersistentStructAttr
(
	struct MyPersistentStruct
	(
		theData
	)
	on create do
	(
		global MyPersistentStruct = MyPersistentStruct
	)
	on load do
	(
		global MyPersistentStruct = MyPersistentStruct
	)
)
custattributes.add rootnode PersistentStructAttr


custom attribute is almost the same as a plugin which has all plugin’s event handlers

IIRC you can also save struct instance as a persistent variable, provided that the struct definition exists (so for example when you have some file with struct definitions in you scripts/startup folder, loading a file with that struct instance saved as persistent variable is okay).

1 Reply
(@davewortley)
Joined: 11 months ago

Posts: 0

Yeah I was trying to avoid having to put a load of extra things in our startups folder but actually this tool is used every day so it’ll be ok…