|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 ) {$ ^1 ]& k0 q8 G6 [6 {; D
3 g1 x2 {: C+ X2 @* u9 N D在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);
" x& z& c' U( O9 w - treenode item = parnode(1);3 q( h/ K+ t# Q
- int port = parval(2);
复制代码 : a8 ]6 E1 R% k! e) F# J5 K- I, G9 w: ~! d
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。' v7 @/ Z, S" P8 u, P1 P" {; Y9 t
在接下来的代码中可以直接引用这三个已经声明好了的变量。
0 q* Q0 V( _" B0 G d$ U) y对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。# Z F7 w f* i" A- Q
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
! o4 U6 _' y( ?9 A9 `' T$ O1 |
1 ]" v) b. y9 y8 U. v$ ctreenode
4 c& l2 ] E9 X8 p' q; wVariable Types& E4 c* y7 |& \( K! A7 p
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.& U' C) C8 l; ?( N
Type Description 9 u1 o- T9 p. t1 c2 Z( r
int integer type
( A- O( j- Z- J. Tdouble double precision floating point type
5 G" |+ m j+ h: B8 ^string text string
3 C# }- J! N* btreenode reference to a Flexsim node or object
) D6 t7 K' ^! _flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。0 E, O; q6 t# G5 ?3 u; C
, N; Y& E5 A5 X& Fcurrent<no parentheses> , f- h0 W6 \( z4 k
Description:
: h1 |) ]* l; R1 _; F9 C# SDeprecated. 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.
7 H, j6 |2 q; v6 H# o7 Y" g. P- w不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
. z6 N! G) N, @/ Y# v' y不解:
$ { o$ } |: X$ G2 i' s1.used...with....是什么意思?
0 M, `" p' D" @/ I4 k6 f. x) J以前current是必须和setcurrent一起使用的吗?8 V! d% R% V- a* }
' |1 E9 _6 ^) e3 z
2.as any other variable type是什么意思?8 i8 }7 m: w6 `, j: [5 Q
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
9 Q3 S5 g, F/ A$ s4 K! eExample:
) v3 W; C- c; \; x- treenode current = rank(model(),3);
# J q+ i6 _, @, b3 s - pt(getname(current));
复制代码 # x- D+ O. D+ W2 R0 W
This sets the object that is ranked 3 in the model to current and prints its name to the output console.
$ d3 A6 W% E$ F$ A/ _) L3 B% L8 h! s' Z5 i2 A$ z( s+ N
3 c: e7 q7 P) R9 s) Q! }: i8 v1 c
ownerobject(node thenode)3 ~( u* w( Z& f [* H
Description:0 q6 V0 ?# y( K% ?! h( M% G
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.3 T! J) X& F: q3 S6 h# @
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.
- h/ v, d. u {, u8 f" D" }4 B该函数返回参数节点所在的实体。. y3 b% c8 U* O. X! P
- f5 p0 K8 Z) s% p
Example:
. ^6 w: K( a/ F% _6 w+ @- string objname = getname(ownerobject(c));
复制代码
+ g" d7 M2 i6 [: iThis 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+ z" y6 h6 W5 GThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.3 C7 E! [1 [% C4 P7 h2 E# E
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。3 t) a$ k2 F8 W$ R! }
' v2 z7 ~2 H& l9 Q, ]& cc<no parentheses>
/ r; J0 R2 w. V3 ]% V5 _; P) aDescription: 6 b( a$ d+ W+ p5 }
This command is used to reference the active node during a function's execution.
- S! G8 [5 Q+ u5 q5 z# ] \6 @' K$ mIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
4 \, \2 h* K: ?2 j R ]If the function is an event function, c returns a reference to the object that contains the event. % d, E( B3 C) m* c0 T1 V
c在函数执行的过程中指向活动实体。
, `& A6 F8 q- a如果是节点型函数,c指向函数所在实体,
I" R( h3 I/ |8 e如果是事件型函数,c指向事件所在实体。5 ]9 w" D; C! i! A- r
Example: - treenode current = ownerobject(c);
复制代码
* b0 V% U& a9 n! I" W% g8 q
) M; ?7 u& |1 ^, f6 Msetcurrent(thing)
; l9 y$ c& V4 oDescription: Deprecated. Do not use.
3 m5 @7 f1 u( \$ C; M9 AExample: /
u: b* p- h0 @* U$ K此命令不再使用。3 v, A; R* J' y/ d
! B4 R' J) S' E! k1 N6 i& A
item<no parentheses> + L. s5 T4 s) T+ [
Description: # p5 [% g# e+ u8 [0 d8 k1 S' J3 w3 T
Deprecated. 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. 0 _; z6 p+ L! V1 x
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
7 U1 z0 i) v% h+ f1 j# D. x# FExample: - treenode item = rank(model(),3);" v8 O! F$ G( }& e: m4 s
- pt(getname(item));
复制代码 4 R3 ~9 ~6 T; _* R( v
This sets the object that is ranked 3 in the model to item and prints its name to the output console.
# z @! m, }/ g% {# l, F% l& }
0 u6 W- i/ [' E3 P, ~/ t' D
5 N8 m: v" ~; i, X5 p9 T: t( qsetitem(thing)
9 Y% l& a- @5 a9 GDescription: Deprecated. Do not use.
9 J' z3 a" p" W* f$ RExample: /
) m6 K7 a, t6 L此命令不再使用。
# @7 o: h; F) g& B' b
* Q9 u. V5 m5 Tparnode(num index)
, g A, \% a6 IDescription: 4 ^+ f8 _3 m) l
This command is used inside a function that is called by the nodefunction() command.' s/ O: x8 y! w% K4 w3 e" K7 k. C
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
" a0 V' A% ]8 W- L+ t) QIt returns the parameter passed to nodefunction specified by index as a node (or treenode). 2 E- B, D0 a. c2 J$ J a
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
9 _( P. F3 B' ^4 V9 @ D7 @节点和树节点有何不同?1 F" w% X+ B y) v) N! }- m$ _
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
7 F" P% G Q; w# oparnode,parval,parstr这三个命令真是让人搞不懂啊...3 s0 e4 D& C Y* p
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 6 J9 @' Z3 o, n7 e: X l, X
Example: 9 g. u9 G6 ^: g- n2 F* v5 n: i
If a trigger/field is called with: . ~( b/ F' K- H7 `, k6 h3 q3 v/ @
nodefunction(thefuncnode, item)
5 N p; ~* V# v s; ethen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码 ; u9 L% I, S7 _9 H# l
' u7 E$ G8 C% ?+ E3 a
port<no parentheses>8 [: H4 P" k4 ]2 T! H0 E ]8 o
Description: 2 O& [6 }7 F2 b3 e; B
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. 6 B: F: c0 ` j" W: W
Example:
( C0 C9 n6 g7 K! _3 r, I- int port = parval(3);
8 O# i" E1 B6 } - pd(port);
复制代码 % r$ a4 t3 s- L) V5 T7 _
This sets port to parval(3) and then prints the value to the output console.3 G* C4 L( F0 w/ t3 B
' V3 j1 X4 H2 t1 O W( X7 I
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|