|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
4 k9 J4 z+ K2 u" @6 j1 J, o0 M
! T' g e. _) o# A" t' u在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);4 L& @) W+ @, K9 U: w
- treenode item = parnode(1);0 X& ^* z7 c; A, c7 C
- int port = parval(2);
复制代码
- n# A% X6 o4 O2 F8 E- ^+ ]# V, Z1 x+ J意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
/ Y# Y% o2 h& d% s2 H" C- k+ h在接下来的代码中可以直接引用这三个已经声明好了的变量。- J4 s- K! G+ C6 f) y3 `* t
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。0 O6 K5 Q/ w( ~7 p/ c
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
- M% B' t, D. ~" a' j6 I1 W; y( `2 O& X/ P: j* \
treenode
" _. Z& f" m# T3 ?) JVariable Types
0 |/ Q6 V% ^ KFlexsim 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.+ y6 k8 |% ^& l% W
Type Description 3 q7 I7 V4 u4 k% h; V
int integer type
4 j! ]0 F- a( |- H0 K7 ?1 C6 _double double precision floating point type
! {8 I! Y& I z# P$ ustring text string
6 n9 N3 f0 G1 q6 R: e0 g. \treenode reference to a Flexsim node or object
- q0 H* ]* N& |2 F" [flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
( A" [ q& t9 i% P! q. Y+ K. D2 ?: H( M& u8 U7 |# r/ e, G& M% x
current<no parentheses>
- Q# q/ b) q2 I% C0 h3 [Description:
, `. g9 Z# @% D& i* 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. 6 X/ j) ?& f0 V/ r# [
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
( h3 I2 O, x3 j1 a不解:7 M1 G& I+ M# ] S# \
1.used...with....是什么意思?8 Z- @, ^: r4 M2 r3 N o: ]( g7 c
以前current是必须和setcurrent一起使用的吗?
' k6 o) o$ c9 b% f7 L& w
$ Z U1 U$ ~0 s& e0 }2.as any other variable type是什么意思?
; r# g5 ^# ]; W! ^/ r4 x7 K# o9 [. b6 f前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
: z- D+ A( e9 E! A# s4 b `9 @- }6 CExample:
+ W! C, K- k* h! o2 Q- treenode current = rank(model(),3);
R; [1 _2 a4 U/ ?: w+ f* { - pt(getname(current));
复制代码
0 C, x! R1 h$ r6 OThis sets the object that is ranked 3 in the model to current and prints its name to the output console. # g$ v) _1 n0 U0 A
& `. j: s+ c: p" i& P+ [
9 |- w& p* I. u$ @, i6 Iownerobject(node thenode)
5 C2 i3 [: d7 W! RDescription:
$ T# T/ E" Z, 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.
1 L7 w3 Q7 n7 ]! I# z' s5 rThis 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." M. ]1 f8 ]. b, Q
该函数返回参数节点所在的实体。
; \0 `# }) t" d! p' J
, R z3 ~. K3 vExample: 4 ~, Z9 I3 w/ |( F
- string objname = getname(ownerobject(c));
复制代码
+ {( x) B" {7 o3 K8 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);
复制代码
6 ? r8 A% t" QThis example is present in most code fields in Flexsim, and retrieves access to the "current" object." m, I7 c" Y" b$ c
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
7 Y3 X4 ^- Y! O) z7 }% J9 k' d9 y! _6 l( G1 o: l
c<no parentheses>
9 q) X+ k# E# e4 }# XDescription:
O' s0 `4 t! h jThis command is used to reference the active node during a function's execution. ; P% m m& O- K% B4 ~7 I( d. ~
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
7 j5 L7 S0 K' M# z* t VIf the function is an event function, c returns a reference to the object that contains the event. & r+ a( I) y, l+ I. V6 {7 Q
c在函数执行的过程中指向活动实体。
5 G5 Q, m7 M( `0 n9 q1 a9 \2 C* H如果是节点型函数,c指向函数所在实体,
" p) \- }: }8 m% b0 n如果是事件型函数,c指向事件所在实体。+ e" d9 w* B. x. q
Example: - treenode current = ownerobject(c);
复制代码 \( U* c" ?" e
* v" j: @- A' g! n; H4 q6 `
setcurrent(thing); m: Y I3 ^ B& K/ S3 E
Description: Deprecated. Do not use. , e: V0 p9 L1 Z9 U" l& Q
Example: /4 B! i/ O0 v5 z. W, e
此命令不再使用。
2 Y5 j% S, y6 T P6 W+ v
- e/ N! J U% L G" sitem<no parentheses>
- c) l5 Z! D" w. m/ M2 x# k+ uDescription:
/ l2 j* F; ?3 G) f& c4 P3 GDeprecated. 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.
" N/ J9 T7 K/ R) {$ a( ^* C# `不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
/ b) S" K7 c6 p4 o+ v7 F) lExample: - treenode item = rank(model(),3);3 C1 k N0 t7 g: z
- pt(getname(item));
复制代码
. T: u6 r2 ?: @ f8 o3 sThis sets the object that is ranked 3 in the model to item and prints its name to the output console. ; f, H1 z8 Q" V$ w5 ]/ Z K
: n2 T7 D- J2 M
4 d1 d) O! s0 o. u+ d% K$ y0 j
setitem(thing)' [6 y- b G' q
Description: Deprecated. Do not use.
. E* j1 s G6 h- oExample: /
' ?- e) L4 T: G+ n此命令不再使用。/ `4 h. @" L9 h1 t7 N9 ^* `
8 ]4 \( l5 Q' F8 {) ^% g5 S
parnode(num index) " J( e7 k/ v, }
Description: ) T% H" ^ p" A6 j/ A; J
This command is used inside a function that is called by the nodefunction() command.
6 G D, m+ `; y, A此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
0 d* d6 i) F# j2 L* GIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
2 f4 F) Z# S2 O' E此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.% R* g( c5 p9 n/ o. t, B; z7 U
节点和树节点有何不同?
- A. C3 k9 T: S% l& w( F9 Y! z5 `) U1 fThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.: l4 c( C2 a* {4 ^7 I( P! ~$ }
parnode,parval,parstr这三个命令真是让人搞不懂啊...
3 m1 Y. q; @' JParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
. }0 e" i3 C/ \/ b* B- H& pExample: ( n' @( V' U* h+ S) R( x" `
If a trigger/field is called with: 0 }: [7 F9 d, W0 C
nodefunction(thefuncnode, item)7 {) l, r2 K, h, Z) L2 e, I4 O
then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码 " k$ Q3 ]9 ]4 J9 I
# L+ d. H* w5 z2 N
port<no parentheses>2 | A+ ]2 f* S0 I
Description: ) l) [* }! R; y5 z; ~& p
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.
" l. \0 C! f# uExample:" m" M6 `4 c; @) P
- int port = parval(3);/ Z- W4 D9 o8 z2 @' m) ^! F
- pd(port);
复制代码 % c$ y. ~ B8 i0 P5 W7 A
This sets port to parval(3) and then prints the value to the output console.* J! ]& U8 F' y( }' {
1 C2 L" Q+ |& m+ S
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|