MAXScript Language Reference > Structure Definition >

# Private and Public Members in Structure Definitions

When defining members (variables and functions) in a struct, the qualifiers public and private can be used to control the member's visibility to users and the Debugger.

Public members can be accessed by outside code. If no qualifier is specified, members are considered public by default. In releases prior to 3ds Max 2010, all members were always public.

Private members are accessible only from within the structure instance. Attempting to access a private member will result in a Runtime error. If the struct is defined in an encrypted script, the member values will not be shown in the Debugger or in error dumps.

The two supported event handlers on create do and on clone do are always implicitly private, even if defined in the public section of the struct definition.

EXAMPLES:
    struct foo2
    (
    public
    A = 1,
    B = 3,
    fn error = throw "ZZZ",
    private
    C = 77,
    fn errorPrivate = throw "ZZZ",
    on create do format "in create: %\n" this,
    on clone do format "in clone: %\n" this
    )

    f = foo2() --creating calls the 'on create do()' handler:
    #Struct:foo2(
    a:<data>; Public,
    b:<data>; Public,
    error:<fn>; Public,
    errorPrivate:<fn>; Private,
    c:<data>; Private)
    in create: (foo2 a:1 b:3)
    (foo2 a:1 b:3)
    f = foo2 a:1 b:3 c:4 --passing three parameters fails:
    -- Runtime error: Attempting to access private member: "c" in: #Struct:foo2(
    -- b:<data>; Public,
    -- errorPrivate:<fn>; Private,
    -- c:<data>; Private,
    -- error:<fn>; Public,
    -- a:<data>; Public)
    f = foo2 a:10 b:30 --passing two parameters works:
    in create: (foo2 a:10 b:30)
    (foo2 a:10 b:30)
    f = foo2 10 30 --passing two arguments works:
    in create: (foo2 a:10 b:30)
    (foo2 a:10 b:30)
    f = foo2 1 3 4 --trying to pass three arguments fails:
    -- Runtime error: Attempting to access private member: "c" in: #Struct:foo2(
    -- b:<data>; Public,
    -- errorPrivate:<fn>; Private,
    -- c:<data>; Private,
    -- error:<fn>; Public,
    -- a:<data>; Public)
    f.errorPrivate() --calling the private error() function fails:
    -- Runtime error: Attempting to access private member: "errorPrivate" in: (foo2 a:10 b:30)
    f.error() --calling the public error() function works:
    -- Frame:
    -- Runtime error: ZZZ
    f2 = copy f --creating a copy of the existing struct
    in clone: (foo2 a:10 b:30)
    (foo2 a:10 b:30)
    showProperties f --the method prints the type of the members
    a:<data>; Public
    b:<data>; Public
    error:<fn>; Public
    errorPrivate:<fn>; Private
    c:<data>; Private
    true

#### See Also

- Structure Definition

- Defining Local Functions in Structures

- Structure Scope While Initializing

- Structure Inherited Methods

- Structure Creation and Cloning Event Handlers