|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 " H7 M7 s9 O) P- {
- P' j+ Y( R0 X- R
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);
1 a' w, s* ? i1 ~: h P - treenode item = parnode(1);
9 U- v8 X# q, c - int port = parval(2);
复制代码 2 Z9 O' ^0 y3 D& v) I( {4 A
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。" ?% s! t0 [$ T/ ?- ^0 Z
在接下来的代码中可以直接引用这三个已经声明好了的变量。
6 H/ z( G! j9 ?; h- O; ?! G对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。( I& B1 y- N0 j. e& j4 ]; v- u
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
- u" F O2 C3 j& Q# E( k/ t s: p
treenode! ]3 r: Y9 E9 k" b2 d: d
Variable Types: H2 |5 S( Q; o5 {( q+ Y; y( W
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.
( [" m& m! B+ d+ }Type Description / Z0 ~- }& h5 W1 _9 m
int integer type 6 g9 D* n# A% ?2 ]1 M
double double precision floating point type
R* s5 P' O! E2 z+ `2 E# u9 t$ |& Wstring text string 5 }/ B# o( s' C' g5 e# c( Q
treenode reference to a Flexsim node or object
$ }2 s. P, N* [, ^flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
}/ ~6 T% Y# g( r' E7 d% O: F% e$ w7 |6 I1 s6 }
current<no parentheses>
6 h! x, C+ z8 }2 ^, I7 |2 K( @Description:
9 V4 `. x1 O, A1 N& W# d F7 u# tDeprecated. 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. 4 V3 }) Y* T7 {8 E( w( J# i$ N
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。+ y: O+ Z( |# P! p. O
不解:
4 Y; x6 A$ Y- h0 K7 f* b e1.used...with....是什么意思?
' t& i5 b# t D: d0 O. _以前current是必须和setcurrent一起使用的吗?
- j+ o0 @. m# }' T/ d+ a' \$ T
2.as any other variable type是什么意思? b5 Y/ r6 S7 `- v& A
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
5 D0 h) u# h. }0 P! FExample:
% @% n, C+ u% a" B- treenode current = rank(model(),3);
' o- Q% T! B n7 a - pt(getname(current));
复制代码
1 _+ `. F8 d8 d) j; Z7 A" cThis sets the object that is ranked 3 in the model to current and prints its name to the output console. 4 c) T8 }7 s- @9 X- u c
( c9 T1 f: ]) a2 X4 ^9 ^" ?3 ?: a$ v/ d' Z
ownerobject(node thenode)
8 C* E( @% ?" i P$ |Description:
3 _! { w, K; D9 F& G- h# J9 yThis 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.
. X6 m, A% R- D C& `, A& z! ?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.
7 }. | I5 d( m* P) }该函数返回参数节点所在的实体。! y# J+ G1 W/ [! I9 j3 R% ~7 [& Z
9 S |- b* M4 e6 B$ K aExample:
% t" Q& _& f$ E& R6 I- string objname = getname(ownerobject(c));
复制代码
5 L9 P7 L7 h4 e. t8 Q( cThis 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);
复制代码 $ F0 k3 K) I1 ^( k$ C, V
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
7 y8 k1 |" P4 I' \这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。' Z2 L3 H9 x+ ^3 q4 \
2 M. ~1 _$ i( d0 V$ a" R( O* t
c<no parentheses>
( D' ~$ W1 C% l9 Z4 _Description:
: ]9 L9 q5 F/ w2 j: QThis command is used to reference the active node during a function's execution. ' v% Y3 M( c. V8 t+ |
If the function was called using nodefunction(), c returns a reference to the node on which the function is written., @0 V& a) I) o2 o
If the function is an event function, c returns a reference to the object that contains the event. ! Q7 ]9 m9 M5 t) z: q4 F( i
c在函数执行的过程中指向活动实体。
" H# h. P5 q+ E! ?2 L! j如果是节点型函数,c指向函数所在实体,# t# H) [% G( a
如果是事件型函数,c指向事件所在实体。: c$ [% a1 b% h. A
Example: - treenode current = ownerobject(c);
复制代码
! h4 W2 J0 K+ r0 X8 [
5 ]1 l* a( k* E( qsetcurrent(thing)2 ^) E" y: o& z/ c1 }: _
Description: Deprecated. Do not use. ) \/ a8 w7 c/ p
Example: /
4 ?1 Z; z; [9 P9 O0 {- _4 \此命令不再使用。
3 i. O Z9 t" B+ G
1 L5 T# I2 r, U; O+ |, Titem<no parentheses>
/ a% K9 |! \! r( X5 `' K# ^& WDescription: 3 i5 ~% C# |0 x( m
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.
4 k0 D3 G9 [8 E; F0 ?0 w) t- o# a0 u不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
: c& ?- l( `& EExample: - treenode item = rank(model(),3);, f/ E3 {. h8 f# y6 [
- pt(getname(item));
复制代码 * t C% u4 ]* o4 L
This sets the object that is ranked 3 in the model to item and prints its name to the output console. + }' I6 I5 Q. h) t/ {
$ c. R5 A2 u2 ?* k" Y' w( {
# k& i. E7 y$ I+ m, \0 z. G( O' msetitem(thing)% }* U C3 U0 s
Description: Deprecated. Do not use. 1 r. T( Y. M6 @+ u" g$ ]
Example: // f" X9 f/ M* {) u) A; f
此命令不再使用。; s0 l+ x* K: r' T; W, P
9 T( s2 k# a* x4 r2 t( B% t
parnode(num index)
0 ?) Q7 }0 i! _; ADescription:
$ @+ N1 \( ?+ J8 LThis command is used inside a function that is called by the nodefunction() command.
9 v/ Q8 ?2 R0 g$ o4 G M$ ~; `此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
6 w1 m6 o% P' V: `/ B+ J* q6 hIt returns the parameter passed to nodefunction specified by index as a node (or treenode). . u$ m: D+ _/ G7 b/ l' O7 _
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.
" w- Q) |1 l" C; i节点和树节点有何不同?9 _9 h$ W6 J5 O: M
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.2 m( C! m7 ?$ N( {; ^
parnode,parval,parstr这三个命令真是让人搞不懂啊...
; ]8 \% H' |$ Q$ Y# s& Z, ~Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
! Q3 m7 p# y* KExample:
1 y8 @2 u; s K; b: z; e+ T, @/ \If a trigger/field is called with:
! b. t$ y; i/ o8 v( }3 p8 t) m# Qnodefunction(thefuncnode, item)3 K) Q& |# ^9 J, Q5 A( w
then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码 ; c' }6 c3 q1 O, A% U
, _( D% N: T2 Q M: pport<no parentheses>" i1 P. c! z9 m# @& K* A" X( C. ]( [
Description: : j- P5 l4 B/ c! f
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.
/ X+ g8 j* C: H( t7 J# }2 I2 ]Example:
' w! C- g# i2 i Q% s& h! W& c- int port = parval(3);' O" M& B0 r* @+ E- g; ?0 n- u
- pd(port);
复制代码 : j! I/ {$ D3 u& G" M, S
This sets port to parval(3) and then prints the value to the output console. i( ~' |# b- P% e, K# I' p5 X
- }, ^ R0 [& g( e: Q
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|