|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
6 |! p5 O2 ^/ v8 ^4 n% M& i! {* y
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);. r! g) ^9 R' O6 V
- treenode item = parnode(1);
- @' }' O6 G. f' r) x6 [) Y - int port = parval(2);
复制代码
+ z4 r4 z$ v7 e& s4 N! l' c8 _意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
9 x! i1 } A, x0 N9 _8 ^" Q在接下来的代码中可以直接引用这三个已经声明好了的变量。
$ Y; U( T; R: h. s' w5 S对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。% |- c! C! f7 k% ?! N" U2 D, G
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。5 f: l2 W! c. u* J) J% n# I
4 ?5 f# v* u" S3 x% e! x8 l6 P
treenode# K- ^. X4 Z9 U$ X
Variable Types
3 g% i6 j2 U$ t2 r* {Flexsim uses just four variable types. Each of the four types can also be used in an array structure. The following explains each of these types.8 H' @2 L3 r" N4 V, ~
Type Description , k* u2 X/ D; o8 `0 V6 Q4 k
int integer type , Z# \$ N; l9 b. j$ w+ e1 B
double double precision floating point type
' r1 W0 E9 N* ]& v7 ]4 Nstring text string
/ L) j* ~* m. Q0 o! p) f& ^treenode reference to a Flexsim node or object
5 b2 d2 o6 ^" Z4 cflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
# u$ L r7 B* H" [+ A" S6 q6 t0 u1 t. g5 n* f( p& K
current<no parentheses> : z% {: [; H" H) |8 S! H9 m6 \
Description: ) @9 g9 e0 j) W4 P
Deprecated. This should not be used as a special command with the setcurrent command anymore. Instead, declare a treenode variable type as current, then use current in your code as any other variable type.
: j6 \7 x9 T; i% F* u. Q% j不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
; C- Z! a: K V3 e( o6 A0 z L不解:! M. i& S6 m p/ `. y H3 J) h
1.used...with....是什么意思?1 q6 o+ w. o# z$ X" U
以前current是必须和setcurrent一起使用的吗?
0 X) \* k+ o7 Q( f( E# o( l. \( ]: k. O' _$ `7 j$ d6 D. M/ ] ^
2.as any other variable type是什么意思?
& P4 ?% y' ~2 I; R/ F: _, F前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
3 \2 m* E/ X2 r: cExample:
# b! J% J3 U$ v2 Z+ p- treenode current = rank(model(),3);
3 I$ d# K9 |1 d8 f+ j Z) C% S* n - pt(getname(current));
复制代码 ' s; r/ A: Z+ b1 m! m: _* X
This sets the object that is ranked 3 in the model to current and prints its name to the output console.
6 D4 M9 q: o; ~' P
) A+ l/ t8 U! ?- `+ n' ~& ^/ j9 u0 n$ `, r2 l
ownerobject(node thenode)
9 F( N* _4 R: LDescription:; y9 V2 l9 ?! F; M
This command returns the node with object data attached to it that is the start of the sub-tree that thenode is in. In other words, it returns the object node that contains thenode.7 R2 e! p5 q1 n4 V+ }0 C
This command is used in most code fields and trigger fields to set the access variable current. In these fields, c references the node that contains the code, and ownerobject(c) references the object that "owns" that node.
" ~, C* R J2 u9 S3 y该函数返回参数节点所在的实体。 m0 r$ u I) {& N4 \; x
3 `, \0 X6 V+ e, n) CExample: 2 Z% t3 I& A7 l' Q( V& J& @! U0 t
- string objname = getname(ownerobject(c));
复制代码
2 _# o7 v% z+ o2 LThis sets objname to the name of the object that contains the node referenced by c. The c usually refers to the node where the code is being written. - treenode current = ownerobject(c);
复制代码
6 s- w3 x* x3 U3 ?/ x% c" q5 ^% z) PThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
6 L' v/ N9 {' j$ |这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。; O6 g% P5 G+ p) V" l# X5 \
: ]7 f+ q5 v- Q5 A: I: z* |2 |* y
c<no parentheses>
$ R2 ^2 B& T& YDescription:
5 Q0 x" Y! \/ tThis command is used to reference the active node during a function's execution.
1 r7 `( t) J- M6 W! B& A9 ?If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
: q& k$ U z$ [/ H' MIf the function is an event function, c returns a reference to the object that contains the event. / I5 Z4 d- u+ z; |1 S' ?' y
c在函数执行的过程中指向活动实体。# @3 ?; C- A* H& [1 ?+ X- D! x, K' C
如果是节点型函数,c指向函数所在实体,
& U |3 m+ }9 l; N如果是事件型函数,c指向事件所在实体。
) F+ p# G* f2 oExample: - treenode current = ownerobject(c);
复制代码
8 ^. ]$ ?% F; O
, H8 \1 r- B) g8 ~' \7 {- q( S" nsetcurrent(thing)
9 F4 g" p. ~" l" p1 M1 JDescription: Deprecated. Do not use. & S! J1 x# Q9 K, j5 R: V
Example: /
4 p! U2 |2 P7 d* j3 ^( J, F- ~; y此命令不再使用。
8 [' P8 X' H& q, N; G4 ?) O! b% p) X2 _$ L" g
item<no parentheses>
# `; a( w$ i$ A* I6 g+ }Description:
- }. T/ _! v2 g5 DDeprecated. This should not be used as a special command with the setitem command anymore. Instead, declare a treenode variable type as item, then use item in your code as any other variable type. n0 u) V3 U) ~6 j9 [, b
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。! E: r1 }, x. @" E6 k
Example: - treenode item = rank(model(),3);
4 F) B. J. @/ w4 d5 Z. y) M - pt(getname(item));
复制代码
, ~" Z# r3 M7 _4 G4 LThis sets the object that is ranked 3 in the model to item and prints its name to the output console. & l. |, K+ x" J
. U* ]5 S4 L; P. U& e6 c+ m* c' g' ~, l
setitem(thing)( I, A Z* T7 \: r
Description: Deprecated. Do not use. 1 e6 j" k: M5 i' P
Example: /1 ~9 |! o& X6 d4 [6 L( R5 q
此命令不再使用。! ]4 `4 I4 ? B7 u" E# f
4 q. c* |9 J& v, Y! V. u
parnode(num index)
! m. L: A" C7 R: _Description:
9 L2 _. d6 M( T9 qThis command is used inside a function that is called by the nodefunction() command.
5 ~- ?, \) V- v! {此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
# e) C' U; l! b+ j' f$ l+ C# _It returns the parameter passed to nodefunction specified by index as a node (or treenode). ) j* ^% ~/ C$ a& p( ^4 v) B K9 @
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.7 `8 \9 o; \$ A w
节点和树节点有何不同?: g! t( F" E3 M
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
2 I+ e+ z3 ^4 A, a) \5 I2 `/ Eparnode,parval,parstr这三个命令真是让人搞不懂啊...& J; O. l, [ y3 E/ r5 I4 n
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
6 d; @5 l$ ?# F, zExample:
( ^( u4 o+ k3 ~$ E: i$ Q* cIf a trigger/field is called with:
/ R) j/ f W; y7 c" V/ U( Qnodefunction(thefuncnode, item)) Z5 h: j. Z7 }
then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码
6 E2 Z/ v( z8 d
1 F5 ~" e9 T) |+ e; G! Xport<no parentheses>1 M7 O. x: U; R6 m. ]7 n
Description: ' M4 Y3 _/ [" i
Deprecated. This should not be used as a special command with the setport command anymore. Instead, declare an int variable type as port, then use port in your code as any other variable type.
: y. u, ^! A0 ]9 Y9 w8 FExample:
: s+ Z4 O9 S1 B( O% M4 Z- int port = parval(3);& `1 u( L; R0 N, `, ?) I% P
- pd(port);
复制代码
7 s- p6 ?6 | G) kThis sets port to parval(3) and then prints the value to the output console.
0 w5 u3 A8 o. h& i" m! L, W/ K5 S
1 R$ r$ L5 c3 t. Q, z不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|