|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 " U/ v, T6 r0 o- U2 [
$ L& q* P6 \/ U) h( Y" |
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);1 N- X, s; y; N! K
- treenode item = parnode(1);$ c9 G/ A& t8 A9 g+ W! P
- int port = parval(2);
复制代码
7 o1 `6 R# ]! j- g意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
G7 M3 R3 ]2 Q V在接下来的代码中可以直接引用这三个已经声明好了的变量。" p) z. ?9 d* G3 R. l
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。0 ~ J' ?6 h1 J0 `& g& H
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
- h6 q. z V9 j
& q! B: D% C" p" H& S4 @treenode/ W8 K0 T( T4 u8 D4 o3 g
Variable Types* [2 H' n7 U4 T k* u8 d
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, G/ c" } ^$ h0 S6 v$ D% w2 ]4 t
Type Description % j, w/ g$ y8 i
int integer type
) ~4 W* O9 P4 l9 ~" u% Wdouble double precision floating point type
2 x7 T* f& X$ i, jstring text string
3 x7 W, M" I! N( |4 q. Mtreenode reference to a Flexsim node or object ( o, q5 t8 y6 f
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。
8 ]/ L) N- b& q/ x0 b+ ^5 V8 Z
( B" n. b$ Y4 Z: d" Ncurrent<no parentheses> v/ ^3 H% G' ]4 O
Description:
* P W3 _: s% K; t6 W1 GDeprecated. 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. & }" i) [ c H3 O& h
不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。! y0 ?) r1 X- `6 ?" K
不解:
; |+ g5 s* a l( W+ F8 y1.used...with....是什么意思?
% e: ^& N" P! E+ a2 P以前current是必须和setcurrent一起使用的吗?
( X, z! e% h3 o3 k6 R+ b/ P+ r% j/ H! ^/ k" H
2.as any other variable type是什么意思?" g/ i" ]' f' ]+ b8 w4 c
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?
* T% I7 s0 J" kExample:
* p6 ^6 X4 I% S) p% `$ A5 ]/ E- treenode current = rank(model(),3);' V7 i* q4 u9 D6 M7 ]
- pt(getname(current));
复制代码 ' z G% d- M( e( V3 n0 W
This sets the object that is ranked 3 in the model to current and prints its name to the output console. 9 n! V0 j n2 L" C1 H- d4 I
4 u3 y, [$ q+ ~8 V1 F9 T
' }2 a% f0 x( j7 n, Y1 E l
ownerobject(node thenode)/ }0 F8 p5 M; i! [
Description:4 _8 o7 |. _0 G6 Y- i3 a2 H. r
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.
0 c, }8 t: ]% V+ N; eThis 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.
9 a; {6 c, _" B8 u' i( Q该函数返回参数节点所在的实体。: T, z3 W8 Q7 l& e
# I9 w' ^* r. _8 t: N+ x
Example: 5 \# n5 @" R8 L7 R: n
- string objname = getname(ownerobject(c));
复制代码
9 ~ \+ R" v: z6 P3 @% NThis 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);
复制代码
0 f. | @$ ^- LThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.
# \6 g6 x8 F2 A8 e# p- z! R ^这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
! g) ]9 N& M4 N$ I# }4 {/ H+ @% U- T, P _
c<no parentheses>- A. |8 n( q% P
Description:
6 a& P9 |( P/ I- p7 XThis command is used to reference the active node during a function's execution. 8 N. Y$ Z# v! q3 ?9 ?9 b- Z$ c
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
; U6 a# j* ^4 \( `) y* `+ {) a6 E; `If the function is an event function, c returns a reference to the object that contains the event. $ E/ K( Z4 N+ p( N
c在函数执行的过程中指向活动实体。
+ V& X2 U# D$ v如果是节点型函数,c指向函数所在实体,, B, b, B1 q, O# v, u( q
如果是事件型函数,c指向事件所在实体。
4 e$ ]* F8 ?' P1 ~Example: - treenode current = ownerobject(c);
复制代码 * L& U ]2 c, V0 O! U$ R
3 w0 g6 s" P" K, c2 O9 @# m& V/ }/ E
setcurrent(thing)
: |5 _* v$ e& u# v9 T7 s# G) MDescription: Deprecated. Do not use. % C, v9 m& W& E9 `& C t
Example: /
- x% [ ], q/ s此命令不再使用。4 U e8 j" V7 l: o& p6 A
: y/ i: L) @6 K$ L; n0 _8 Y! Mitem<no parentheses> / u; `+ z! p7 E
Description:
7 _9 o( I& C7 }1 }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. ) a3 w! N5 T- W% `" Z& |
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
- a$ A" |$ h( J$ k' IExample: - treenode item = rank(model(),3);- }% ?( g# q4 F$ `. Y+ `( b+ d
- pt(getname(item));
复制代码
- h5 A. c* c ^+ lThis sets the object that is ranked 3 in the model to item and prints its name to the output console. " l: K3 V7 \: Z( S
; R8 E' u$ N' D, Q9 b4 k0 D/ L0 S2 T: z( E$ [, @
setitem(thing)
b- I5 [6 P) J, R3 j: B) C7 ADescription: Deprecated. Do not use. % {' O4 H6 x$ _/ s4 T% ]7 p
Example: /
! w; U% P9 O1 {- g+ v N此命令不再使用。
$ H8 P5 }* |/ y E
; F5 ?, e1 Y& A. N4 M8 j/ Gparnode(num index)
; s# F1 y1 R! h+ aDescription:
, ?$ p1 j3 Z$ I( {- KThis command is used inside a function that is called by the nodefunction() command.5 |# C4 R2 j. I
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?0 b- G& Z/ d; R( Y
It returns the parameter passed to nodefunction specified by index as a node (or treenode). 3 l# d1 L+ @* J+ e7 ~* d. A
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.3 \0 S: ]6 f1 D# K9 k! o
节点和树节点有何不同?8 ^0 P9 u0 q& u3 P) R
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
/ m8 r. z& R: \: Y& Uparnode,parval,parstr这三个命令真是让人搞不懂啊...9 Y& k8 D9 Q' e- N* y: Y9 f) M
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. ' I/ \: m7 C* o/ w8 R( X# w
Example: ) C7 x5 [6 I/ F7 @+ k- V
If a trigger/field is called with:
% a$ c6 Q- ], z- M9 q+ O2 X6 unodefunction(thefuncnode, item)
; g' H1 w# f# |then within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码
6 }3 [0 k+ b( G7 G3 L
0 p5 c# C2 a* P9 y+ eport<no parentheses>
) P$ u& Y1 d* ]Description: 7 \- }+ ]+ k( d8 Q* ^
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. , ^4 |1 x' m9 L( O7 t
Example:$ u% W* T$ N# {! U- G* u1 d2 Y
- int port = parval(3);
B3 ~( u1 v" h/ D- R/ k - pd(port);
复制代码
0 g0 K0 u ?# o* r* tThis sets port to parval(3) and then prints the value to the output console.9 S5 C0 ^! i" E# ]
) H( |9 ~. u6 }7 {9 v! y) d不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|