Notifications
Clear all

[Closed] Struct public get, private set

I’m sure this is a no, since they literally are Structs but,

Does someone have a good way to prevent a Initialized variable in a struct from being accessed after creation?

So, basically making a class constructor of sorts.

If i put them in the private field, then they can’t be accessed upon initialization, but if they’re in the public field, then they’re generally exposed. I have a ‘get’ function, but with the variable also exposed for initialization, its kind of mute.

In an Ideal situation, below is what i’m looking for.

struct foo
(
private
data,
public
fn GetData = data

)

foo data:MyData

4 Replies

What causes this desire to protect variables? from whom?

With a function call, i can flag updates if the data changes.

If someone just access the properties, i’ll never know to update all data that ties to that property.

This is more to protect other people on the team from misusing the tools. Unless there’s an event handler for when data changes that I don’t know about?

The average user cannot change the values ​​of maxscript structures without using scripts. And nothing can stop the advanced user in any case.
I spent a lot of time working on fool-proof for my code, but in the end I decided that the fool should take care of himself.
Therefore, I say to all my users: do not break this if you want this to work.

A good way to look at it. Thanks man.