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() --
|
--> #Struct:foo2(
--> error:<fn>; Public,
--> c:<data>; Private,
--> b:<data>; Public,
--> errorPrivate:<fn>; Private,
--> a:<data>; Public)
--> undefined
--> in create: (foo2 a:1 b:3)
--> (foo2 a:1 b:3)
--> OK
|
|
-- 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)
|
|
in create: (foo2 a:10 b:30)
(foo2 a:10 b:30)
|
|
in create: (foo2 a:10 b:30)
(foo2 a:10 b:30)
|
|
-- 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)
|
|
-- Runtime error: Attempting to access private member: "errorPrivate" in: (foo2 a:10 b:30)
|
|
-- Frame:
-- Runtime error: ZZZ
|
|
in clone: (foo2 a:10 b:30)
(foo2 a:10 b:30)
|
|
a:<data>; Public
b:<data>; Public
error:<fn>; Public
errorPrivate:<fn>; Private
c:<data>; Private
true
|