|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
" |" Q0 D7 ], n8 J9 R2 S/ ~% u
: c; x3 E5 x) p4 V7 i s在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);; V) ?7 i+ E0 s- e" r& f
- treenode item = parnode(1);
$ z. f+ S4 g( T, {' g$ r0 Z! r) f - int port = parval(2);
复制代码
0 h3 S0 t- w- Z4 Q% L" E意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
3 Y( {+ j* _3 c+ M. e在接下来的代码中可以直接引用这三个已经声明好了的变量。4 w( }& j5 f# X; \
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。; O5 i0 l+ B( E: ?% G, I- \7 G
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
?+ j) a0 V2 a! f, s8 \ u; C5 B
3 I9 i' p* i! J! ntreenode; ?8 J% L/ c+ ?) i7 M
Variable Types# h& i! ~8 U }$ e
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.
* V) D6 s2 Z# p( r, f2 p) y- _Type Description 4 y; k7 H# t; h1 r! b! k/ a
int integer type 8 @( l9 Q0 h1 W& l
double double precision floating point type
. H1 C' X& d, Dstring text string 7 u4 ^* }0 V) k8 c
treenode reference to a Flexsim node or object ; j- E# {% k) q2 C: V, A
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。/ }5 q/ h. f% D
$ l% Q1 R7 k( S7 U4 C1 v- jcurrent<no parentheses>
, R' n. X& E$ w* K. D, kDescription:
! }% A7 l) C6 p! F JDeprecated. 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. " d" F+ Q( I4 x* x- _5 y
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。) a0 z8 d. v- \) L/ B- w( f
不解:, N- h3 e' M0 r& f$ |: U
1.used...with....是什么意思?! A* S; |3 G- N7 H& Q7 I
以前current是必须和setcurrent一起使用的吗?2 \7 K3 Q7 L! f& d
6 ~& M, D8 p% X3 ~1 d' V2.as any other variable type是什么意思?
6 H o% p: G4 C% W4 b7 c3 o前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
9 N/ u/ j) H) [( E( I0 U$ n+ B$ [Example: ' B$ g& T5 V) a' ~8 r
- treenode current = rank(model(),3);& \* d1 A! u4 _3 ?
- pt(getname(current));
复制代码 + Q" L, g5 r i1 J& E& ]
This sets the object that is ranked 3 in the model to current and prints its name to the output console.
- w& u% Q7 N; c3 u& O
& |1 {% {6 Y& V; [: d% R; J3 K- {( u6 t/ e6 I! R5 x
ownerobject(node thenode)
2 c+ f. f" J2 E' PDescription:
' C6 V% _8 w. z5 {* d# `- m0 D J: VThis 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.( j& g: v Z$ y) |$ Q* {9 A0 m0 v
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.1 q1 O, Y0 m0 a1 B$ X7 L2 B( \
该函数返回参数节点所在的实体。1 z* Y$ i9 U0 D: y5 i/ c( ^, E$ f
7 i" U% V8 J1 P( @
Example: / ~, F9 A9 r( M1 f! G
- string objname = getname(ownerobject(c));
复制代码
, _ b6 t6 p8 s6 c- yThis 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);
复制代码
2 i& H2 r1 t* W' XThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.. B& o. p" Q) u1 }
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
( @/ r8 C5 }/ G; X. R) k! ^; w$ e3 v! N5 W
c<no parentheses>1 E5 a7 S6 i) {4 w: L" b* H. g* ~
Description:
( Q0 m2 h0 j9 F( D+ [/ TThis command is used to reference the active node during a function's execution. , ~# d4 u: J" y; F& e$ A
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
" x, I ^' s1 ^9 ?) l m. @If the function is an event function, c returns a reference to the object that contains the event. 2 q: j# @; r0 I$ Y
c在函数执行的过程中指向活动实体。+ I0 R! _" N+ v5 Y
如果是节点型函数,c指向函数所在实体,! ~3 ]3 \% K: X, F
如果是事件型函数,c指向事件所在实体。
" W; h! Q- I9 u5 U( N: q# WExample: - treenode current = ownerobject(c);
复制代码
2 f- j/ s, _& r% w# Y+ u# T3 K
9 ]7 P- d7 M# k/ d$ dsetcurrent(thing)* l$ d- o6 |- |8 n7 T( M
Description: Deprecated. Do not use. : e' r% Z4 G! ?% \
Example: /
4 a& G1 s+ x( ]! G) h此命令不再使用。
, e' m$ C* Y/ S/ I! r% ~
1 y) B, ?9 d- d; n) S# _, |item<no parentheses>
6 ?# T4 o, }' {1 \" E) RDescription: + ]. t0 M' h, p, G" m1 y5 x
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. 5 k% `. I6 p5 f% D1 r: T( h7 m( x
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
+ x5 P4 |' J1 a) M$ L% ]8 s* vExample: - treenode item = rank(model(),3);; V* m2 u/ _7 O6 Q- P
- pt(getname(item));
复制代码 ( u# m9 N) T% G
This sets the object that is ranked 3 in the model to item and prints its name to the output console.
) b+ N9 O" X% _& k8 T4 j4 S& \0 {; A
7 g2 E9 K& K" T% K% }1 @; L: h
' P1 `& K- i, @3 l7 c1 r; e6 ` Hsetitem(thing)
5 g, J4 a l5 N9 _# }& wDescription: Deprecated. Do not use.
% h+ T9 J; q* @. f% ^5 q& bExample: /
! N( z& B2 I8 v0 t* O! d- r$ x此命令不再使用。
" D2 Z# G7 S. `2 a* W& P* ~6 {3 Y4 T4 F% `
parnode(num index)
. K* P$ D* g# T$ N; _1 g5 yDescription:
! X/ C1 o" Z) s2 w+ ? vThis command is used inside a function that is called by the nodefunction() command.8 C4 w( E2 ]9 ^) j3 v: s$ W; u( x
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?) c! c8 ^' E3 R0 q, L- b' Q
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
& u( N; z6 \ W% j! J) ^此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
2 M; b7 O9 D8 @* S/ M4 D节点和树节点有何不同?
' p* o3 q: n M6 [7 k1 O% j; gThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
4 A8 F, d% r( R" x5 t& `parnode,parval,parstr这三个命令真是让人搞不懂啊...
; `1 O, C J4 f% }0 X# jParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. . B6 d8 M! L- ~8 d
Example:
# d; N. q4 b9 {( h& }) aIf a trigger/field is called with:
) O( V. P+ k, q- bnodefunction(thefuncnode, item)
. }9 H9 g; I% Q, ~then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码 0 A1 D& W' c0 z+ q% i
+ m' v1 q1 q+ A/ x
port<no parentheses>
+ r9 A/ T$ E8 ADescription:
* _& f! j3 b$ K4 _' @, DDeprecated. 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. , n3 O9 Z& H7 X1 S( F' I. E
Example:; o1 }5 k J( @. k
- int port = parval(3);8 _4 t& J0 {5 Y) u
- pd(port);
复制代码 0 T4 c& d) Y3 n* e( n7 ~1 {
This sets port to parval(3) and then prints the value to the output console.& S0 r7 |8 U$ o
4 Z! j$ N8 X# p Q; q
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|