|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
( I" @# ? k e, o* [/ A* A/ d% w! R# _
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);$ ?6 i* ~, G5 F1 [; L. Y/ P
- treenode item = parnode(1);
7 y6 X; Z2 T* y0 J4 F/ L# e1 Y - int port = parval(2);
复制代码 " e2 d% I( ]7 p# c/ R, v/ P$ Y
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
; X# O- Q$ g( z. B# q在接下来的代码中可以直接引用这三个已经声明好了的变量。4 d: G: F, I p$ A3 Q: x6 Z
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。( _% t; W8 k1 ~1 ~
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。! U1 ^ S" `2 [. ]: A; P% |
; A0 I) @: f: P7 ttreenode
! @) P7 J+ @6 J1 G( c$ O# rVariable Types# J! R9 W0 O( a/ R2 F. w/ Y
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.- v4 J/ m7 h6 _& o- t
Type Description # w6 m1 }/ y* X
int integer type
% I- d( _0 y( K# r, V# \1 k/ {double double precision floating point type # v( E7 X1 d6 C
string text string * u8 G* v' B9 t/ J
treenode reference to a Flexsim node or object
2 V6 T ^0 p! Yflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。% h/ t% Q/ S* V* Z& x, z$ b9 M
/ E' m8 s4 l6 `" v
current<no parentheses>
+ e9 X- C% |# ^Description:
$ s9 k) K! m4 VDeprecated. 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.
1 ?/ I9 s. k% y0 \9 R ^% G# E不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。. w% N; U; G( `
不解:
) E2 s/ z6 ]& J2 h1.used...with....是什么意思?
$ J, P5 B/ }2 A' F以前current是必须和setcurrent一起使用的吗?% W% I5 B/ Y+ }/ S: e- s6 p5 @
% O! O0 B C5 n) E1 {/ [( n. W2.as any other variable type是什么意思?
* O7 z; {' l8 s% C2 a0 ^前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
W) k4 t; q( h) R7 S% f( B _Example:
/ s9 p0 }& i: c' }; L% y: o- treenode current = rank(model(),3);/ o. t3 O) k/ S+ ^
- pt(getname(current));
复制代码
6 V& h# K. E" a0 Z8 R0 Z' H+ U* oThis sets the object that is ranked 3 in the model to current and prints its name to the output console. ) k; ]2 O! B& c+ k# s
1 c B7 P& F9 o- v$ K6 b( i6 R/ b% c0 s* g8 V
ownerobject(node thenode)
- |2 k. H( Z0 aDescription:
* O8 C) k" O- Z0 X: h" fThis 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.6 J3 z2 X1 ^. h. ?5 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., |" n% {$ V! Q/ G. Q& x
该函数返回参数节点所在的实体。
/ V6 Q# Y3 h- V6 u2 X; {3 V/ y5 T0 J6 K9 h/ R
Example: 6 J' e& X$ v8 w- a( p3 i
- string objname = getname(ownerobject(c));
复制代码
7 L1 t9 Y6 B; e- q! }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);
复制代码
# B4 ~- _5 y/ ]) {8 CThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
& P2 `% `. ]: S2 {2 Q( T这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
: P! z" |9 f& a) a7 R7 R7 _0 b$ i# ^8 X7 t; D/ e5 {/ V& E O
c<no parentheses>! p7 N* |2 B- E% C0 f% [
Description: 1 Q. U/ W3 m( w h5 \
This command is used to reference the active node during a function's execution. $ i' q$ V# J! ?: ~
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
' E$ A1 V8 z1 j- O, x' HIf the function is an event function, c returns a reference to the object that contains the event.
# @/ ^: Y) x) N7 v4 j$ \c在函数执行的过程中指向活动实体。
; z& y" z3 H) l7 x2 F如果是节点型函数,c指向函数所在实体,
9 a+ m3 V5 v+ s9 M I如果是事件型函数,c指向事件所在实体。- {( B& q% f1 z$ P' {" z4 |
Example: - treenode current = ownerobject(c);
复制代码
4 J2 T7 P) P/ D8 x" s; v7 B
+ ~: g& f6 G- e+ e2 X6 A: b4 w& \/ usetcurrent(thing)
! S. h1 r2 G7 a4 I) f MDescription: Deprecated. Do not use.
8 H5 R5 `* ?+ t* B% ^% Y; gExample: /
! `4 d- Y: p1 ` A此命令不再使用。
+ y8 Z5 l5 k( _& Q. p9 ^4 Y \* [ p f5 a
item<no parentheses> / z I% D4 l$ h/ }& i7 E
Description: . y; ]% |: H+ G7 g2 E- y% 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. ; J5 i* o5 w5 l6 D" y! ^! o% s& [
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
/ c* @0 H) L4 J$ H: B+ W: ]. wExample: - treenode item = rank(model(),3);; m, ~5 J2 F6 W3 R# l4 I# A' g1 }
- pt(getname(item));
复制代码 " I4 v0 ? h- _, E$ B
This sets the object that is ranked 3 in the model to item and prints its name to the output console.
9 v8 C9 ~( B2 y4 N, m3 w% u! z4 y" r& j& d5 t5 Q
, I6 H0 [6 v- G4 M, @, X4 I/ c
setitem(thing)" P# Y* z* ^- W
Description: Deprecated. Do not use.
! y1 c- z2 N5 ~Example: /$ X& i4 R5 J) L) E. K6 R% A
此命令不再使用。
6 e* Q5 ]% c7 H+ d. L0 n% K% X5 r5 P1 D1 ^. O6 P7 c; j
parnode(num index) % T( U/ m- O3 ^5 {6 k2 E
Description:
1 a; m" g H3 U( ^" N" b9 ]8 l. |7 b8 xThis command is used inside a function that is called by the nodefunction() command.# s/ e/ ~ J2 ?0 f8 k- U- T7 c
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?$ R/ x0 b4 _' k/ p
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
" s4 [* J' X4 v/ r$ S- t- Y此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.6 F& H7 T$ w2 c7 a. V
节点和树节点有何不同?
' z) t" @, t7 f' v+ [' wThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.* H3 ^: b9 D, p
parnode,parval,parstr这三个命令真是让人搞不懂啊...
7 c! F: U: m }5 y1 _Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. ! \4 u- I* q$ d" ~6 N
Example:
; Z' y: q! R8 n2 A! ~) qIf a trigger/field is called with: % L' j5 T$ `" r7 z, ]
nodefunction(thefuncnode, item)# w2 j' F) H% A, y q( U. c9 K
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& s9 S9 i0 j' o( K$ k% M3 J
% k2 W% ^+ w, V Aport<no parentheses>5 U% N T& c" r/ }: U3 Y1 ]
Description: + n9 }: ^- g+ I- m; 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. / S: ~2 b: y2 J/ e
Example:
9 m3 G) s( U, b: I- int port = parval(3);
2 k3 U8 Q9 R; b( ?* N - pd(port);
复制代码
4 y5 L% h3 d* Z; q2 a; d( BThis sets port to parval(3) and then prints the value to the output console.7 V! V, q8 R1 |! @
B5 T6 ]7 h7 B5 Q) q/ L不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|