|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
1 U" j* b: J% a( F
! P2 o3 a: N* [) S& F2 e" l在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);+ l& Z6 O& Z, c/ F, x8 D
- treenode item = parnode(1);" W- }8 `# J: F5 t/ I$ u( p
- int port = parval(2);
复制代码 1 |. ^* b H& g5 D
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。2 A. Q4 G0 y. j0 ^- m/ ~4 u
在接下来的代码中可以直接引用这三个已经声明好了的变量。2 W2 \! a* @. `- P
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。7 P1 H" M0 K1 s9 b% a) }
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
& u3 i( j0 I9 X' {& U) \8 }5 _# T+ H, }6 U6 F
treenode/ f% Q7 V# ]& F- ~
Variable Types7 e) o: w B! M; p; m0 W* S
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.+ w, r. }# A0 s% P; B; L- ^
Type Description 1 M# ?9 U" |+ @" b, s `
int integer type ' n; o7 y+ U% L, A% m
double double precision floating point type 0 g: M- }& P0 m) s* A
string text string 0 G; X; ]/ f7 D# l( K0 D3 G: c; k
treenode reference to a Flexsim node or object , S( G1 A$ R5 f+ k; Y# R
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。, J* B/ b7 X8 e; O# j: w
" L- Z! H4 V, ucurrent<no parentheses> " C. S) d2 I) T! v, U+ M' X/ S0 y# S
Description: 0 j; F8 b2 Y0 ^0 F1 J% B
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. , Z- x6 u K5 L. s
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
% p4 V$ }) Q# _2 V, W! j1 o4 b8 M( g不解:+ E( T. V6 _# |$ l l2 R& j
1.used...with....是什么意思?
! f* a' G u+ M5 T: O以前current是必须和setcurrent一起使用的吗?
' Z3 W9 [) \1 R# e+ U8 Q% x& Z: h d. I
2.as any other variable type是什么意思?
5 E2 J( Q7 ~. K9 X7 S前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?5 t& P1 C! b {) e+ R$ {' V
Example:
6 w" v: b- }5 ?; {' S( s, l- treenode current = rank(model(),3);
8 V6 j/ S- l' `7 J& f - pt(getname(current));
复制代码 % w0 _) u( d& F7 h
This sets the object that is ranked 3 in the model to current and prints its name to the output console. V2 b Q. k2 L0 e" h
- t1 }2 x2 r( s& S0 J( D9 H9 Z; L
0 L2 q2 m0 ~9 gownerobject(node thenode)) s& w6 y/ P6 M1 @" i7 x) v+ k3 S
Description:5 \5 I+ t) s* Q! b$ }+ U. y7 [5 A6 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.) x( B2 P- o8 S+ O/ f% g: D! a
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.* E6 n% J1 m; @& n A1 e0 y
该函数返回参数节点所在的实体。
) b h* x7 [. G, F+ l5 M0 ^3 g& J
* E. _1 J7 J! R. b2 z1 V& wExample: " P. Q2 D+ n* Q- _& M+ H
- string objname = getname(ownerobject(c));
复制代码
9 R6 f4 g5 f" |* w: l4 b# B# @This 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);
复制代码 # v- u4 E+ k* G% L p
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.. H( @+ Q2 d) Y( u
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
4 p7 d2 X$ ]' i7 U) u! i9 S
: S! b( H0 C. l( Fc<no parentheses>$ ]. Z2 ?. g6 [6 T/ l
Description: ; X8 {9 L; [5 g5 c
This command is used to reference the active node during a function's execution.
0 X+ s" G/ @& g3 j- k- ?If the function was called using nodefunction(), c returns a reference to the node on which the function is written.% S5 J% y1 N- t# [
If the function is an event function, c returns a reference to the object that contains the event.
! U9 U z) Y8 Q8 e3 }4 jc在函数执行的过程中指向活动实体。" O' R( q1 e0 g: Q, }: b4 _+ L5 Z
如果是节点型函数,c指向函数所在实体,
* v( w' Q* J+ [7 n2 a( O) Z) D9 M- M如果是事件型函数,c指向事件所在实体。
# y3 K. w/ x$ m( iExample: - treenode current = ownerobject(c);
复制代码 & p5 o3 B6 b9 I$ R
1 ^( o: k' h+ y9 Wsetcurrent(thing), D( i! P) \9 _2 B+ D0 {7 H
Description: Deprecated. Do not use. * q2 n/ V2 T( V/ y8 d7 y" T
Example: /$ ?& X5 s5 D6 j: g5 l
此命令不再使用。
6 ~" C' b+ V6 m( b! c% i
2 @! V$ [" ^9 T2 [item<no parentheses>
3 Y: P) a3 ^9 x2 k& ]) Q! hDescription:
1 w, a4 X( }& ]" O6 m. cDeprecated. 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. # W7 _: R4 m$ |
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。3 |8 a. ]2 g# Y, H
Example: - treenode item = rank(model(),3);9 K) Y+ ~* i3 `1 O7 s$ f
- pt(getname(item));
复制代码
# B( j- m) k7 g& p( PThis sets the object that is ranked 3 in the model to item and prints its name to the output console.
( L5 Z# w% e Y' P; G- |1 _, B. q" n9 M0 n2 X
8 _: ^! e4 W* Z5 v! i! }3 ~' x
setitem(thing)
8 c6 Q& K6 t8 H: k$ SDescription: Deprecated. Do not use.
6 W: v: c6 L, PExample: /
5 ]6 O t: A- H1 _此命令不再使用。
/ D; E7 K1 J$ }. F* f. t
2 @" w- \% |! e% ]' Mparnode(num index)
) w, f, L- z; c1 @0 }/ L% @Description:
! u" k0 K% S6 r! W2 LThis command is used inside a function that is called by the nodefunction() command.+ K/ z) a1 _6 e6 [8 A- l
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
4 l" O8 Y5 p9 ?# s0 h; _" EIt returns the parameter passed to nodefunction specified by index as a node (or treenode). 3 }# ~8 q+ L; i0 y9 a7 x" u
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
% b: J! s4 [3 B! V4 M$ R! h节点和树节点有何不同?
1 j2 @' S! i+ ?) `) NThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
; ~7 d- L- G0 W) Q6 Mparnode,parval,parstr这三个命令真是让人搞不懂啊...
1 q% P; L2 G; _Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
) V+ f. A8 r9 wExample:
! ]* X4 s" H/ @' ~8 A- ?0 L' VIf a trigger/field is called with:
$ [6 j8 I& X* K/ g( Tnodefunction(thefuncnode, item)
" j8 v( z# C5 Q& [: E2 }+ Ythen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码
4 S$ E" Q+ _/ L" V& W8 ?$ q
/ U3 W) W3 R" Rport<no parentheses>
! ^- d: _) o. FDescription: . | P4 a8 W5 p+ y! j a9 o5 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.
5 b# f& {9 I* N- ]1 GExample:9 i/ @% I6 s1 z: w, X4 f
- int port = parval(3);0 p& Q* |4 B& m' c% [$ n- w
- pd(port);
复制代码 3 ?1 T- G j O! L
This sets port to parval(3) and then prints the value to the output console.: Q! N7 V+ @, q6 z
/ V$ m) _' z2 E" o! s9 @7 r' |
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|