Notifications
Clear all

[Closed] How to make a public struct member read-only in maxscript?

hi guys,
as the title said, is it possible to have a read-only public struct member (variable) ?
i’ve googled it but didn’t find any workaround for this. If it is not possible in maxscript, how do you guys trick it?

thanks!

11 Replies

no way! you can’t do it via MXS as well as via SDK

the only solution is to make this property PRIVATE, and make public ‘getter’


struct A
(
private
        value,
public
        fn get_value = value
)

hi Denis
sorry i didnt include the code,
here it is the code:


struct s1
(
    private
    title="a script",
    version=0.1,
    var_a=1,
    var_b=2,
    
    public
    subStruct,
    publicTools=
    (    
        struct subStruct
        (    
            fn getTitle_fn= title,
            fn getVersion_fn= version,
            fn totalVar_fn =  var_a+var_b
        )
        publicTools= subStruct()
    )
    MyDir="",
    SaveBackup=true
)
theStruct= s1()

i hope you understand what i need to achieve with the code above.
the function is not permitted to call private member from its parent structure. and i cannot move the public ‘getter’ to the main structure.
… and you said it isnt possible in mxs… i’m sad now…

Or Did i do something wrong. Or Do you have any other ideas?


struct structA 
(
private   
   title = "Structure",
   version = "1.03",
   placement = [200,100],
   
   fn getTitle = title,
   fn getVersion = version,
   fn getPlacement = placement,
   Info =
   (
      struct Info
      (
         getTitle,
         getVersion,
         getPlacement
      )
   ),
   
public 
   thisInfo = Info getTitle:this.getTitle getVersion:this.getVersion getPlacement:this.getPlacement
)
a = structA()
a.thisInfo.getTitle()
a.thisInfo.getPlacement()

1 Reply
(@noel20)
Joined: 11 months ago

Posts: 0

hey Denis, i used that way and solved the problem but there is a thing confuse me.
How could ‘This’ be an instance of the main struct? You didnt declare that variable first but it works, in another hand it will fail if i change it to any other variable name (undeclared variable)
am i missing something?

and one more question


struct structA
(
private
   title = "Structure",
   version = "1.03",
   placement = [200,100],
    
   fn getTitle_fn = title,
   fn getVersion_fn = version,
   fn getPlacement_fn = placement,
    fn CollectSomeObjs_fn = print "CollectSomeObjs",
    fn AddCtrls_fn = print "AddCtrls",
    fn TwoFnCombined_fn= 
    (    a.CollectSomeObjs_fn()
        a.AddCtrls_fn()
    ),
   Info =
   (
      struct Info
      (
         getTitle,
         getVersion,
         getPlacement,
         TwoFnCombined
      )
   ),

public
   thisInfo = 
   (    Info getTitle:this.getTitle_fn getVersion:this.getVersion_fn getPlacement:this.getPlacement_fn \
        TwoFnCombined:this.TwoFnCombined_fn
   )
)
a = structA()
a.thisInfo.TwoFnCombined()

when i call a.thisInfo.DoSomething() why do i get the result twice?

hi Denis, sorry for late reply
thanks for sharing the idea! i’ll implement it immediately

let me ask once more, a little bit off-topic (tell me if i should create a new thread)
based on my code above, at public variable SaveBackup, is it possible to lock it to BooleanClass only? so there will be a warning if a user change it to non BooleanClass?
i’m thinking of dotnet timer but i’d like to ask the doctor first

you can’t preserve any public property from redefinition to any value…
so i suggest to stay with what you have but check SaveBackup to anything true. everything else is false.


if SaveBackup == true <or SaveBackup == 1 or SaveBackup == "true"> do <backup>

yeah i already did what your code do. Many thanks Denis!

‘this’ is a predefined variable that yields the instance of the struct (same as for scripted plug-in).
If you get the result twice it’s possibly because you are calling the function from the listener so it shows the function returned value and the result of the command typed in the listener (which are the same if the last instruction in the function is the returned value).

hi Aaandres,
About the predefined ‘This’, never thought of it is applicable to outside of scripted-plugin… makes me need to read the documentation more often
and the get the result twice, what a stupid thing sorry. Pressures sometimes makes me using my brain in a wrong way.
thanks for your help

Here’s a way I use sometimes to create a dynamic ‘readonly’ parameter struct

Page 1 / 2