構造体定義における Pirvate メンバと Public メンバ
 
 
 

構造体のメンバ(変数と関数)を定義するときは、修飾子 public および private を使用して、ユーザおよびデバッガに対するメンバの可視性を制御できます。

Public メンバに対しては、外部コードからアクセスすることができます。修飾子を指定しない場合は、メンバは既定値で public であるとみなされます。3ds Max 2010 よりも前のリリースでは、すべてのメンバが常に public でした。

Private メンバには、構造体インスタンス内からのみアクセスできます。private メンバにアクセスを試みると、ランタイム エラーが発生します。構造体を暗号化されたスクリプト内に定義すると、メンバ値はデバッガやエラー ダンプには表示されません。

サポートされる 2 つのイベント ハンドラである on create do および on clone do は、構造体定義の public セクションで定義された場合でも、必ず自動的に private になります。

例:

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() --'on create do()' ハンドラの呼び出しを作成:
#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 --3 つのパラメータの受け渡しに失敗:
-- 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 --2 つのパラメータの受け渡しに成功:
in create: (foo2 a:10 b:30)
(foo2 a:10 b:30)
f = foo2 10 30 --2 つの引数の受け渡しに成功: 
in create: (foo2 a:10 b:30)
(foo2 a:10 b:30)
f = foo2 1 3 4 --3 つの引数の受け渡しに失敗: 
-- 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() --private error() 関数の呼び出しに失敗:
-- Runtime error: Attempting to access private member: "errorPrivate" in: (foo2 a:10 b:30)
f.error() --public error() 関数の呼び出しに成功:
-- Frame:
-- Runtime error: ZZZ
f2 = copy f --既存の構造体のコピーを作成
in clone: (foo2 a:10 b:30)
(foo2 a:10 b:30)
showProperties f --メンバのタイプをプリントするメソッド
a:<data>; Public
b:<data>; Public
error:<fn>; Public
errorPrivate:<fn>; Private
c:<data>; Private
true
関連事項