|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 5 O2 N- v. q9 N3 ~$ D+ n+ b1 t
" p$ }# T5 @: [4 C
在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);
7 L( g4 Y9 U2 ^, w6 r& ]0 a3 G - treenode item = parnode(1);
. [$ Y: f9 W+ M6 E6 U7 s/ }$ ? - int port = parval(2);
复制代码
4 D; W" w: X' T }& e0 b k: m" ]1 H! ?意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
* L5 j" }' Z4 j; k$ w在接下来的代码中可以直接引用这三个已经声明好了的变量。1 D8 y5 F3 n5 h. l# Z; n5 h( ^
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
( g' V6 g, M' |. u3 }+ [下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
* h6 [% A& k/ m6 w$ ~5 R+ Y* D8 A! h# G
treenode
3 Q5 Q3 m; A' a% bVariable Types
/ z0 I5 \: m7 Z7 s# Z. @1 U: AFlexsim 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.
+ R( F/ \3 s- ~1 @0 xType Description
! {8 d1 _4 s5 hint integer type # Y0 p8 ~% O2 b, W. I
double double precision floating point type
& j! o- k0 k8 T7 n& ustring text string % r' j$ a# }, ^; V( {5 ?2 o/ W
treenode reference to a Flexsim node or object 0 w5 A0 Q2 ]# Y8 \4 H
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。! n' s: m( @ o+ m4 o! k
: z- N; v. q: p
current<no parentheses>
9 \7 j5 j! B* A) i! mDescription:
* V6 x/ {0 O$ |- O# v0 j+ _Deprecated. 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.
, G) m! r N" `* x不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。
. ~: h7 _* Y* R5 i( c/ g' m不解:5 A8 k# S4 _; L( P* j
1.used...with....是什么意思?) I3 U2 \9 _: y7 r3 _; F5 t
以前current是必须和setcurrent一起使用的吗?! p5 m- ]4 ~/ A4 z. k9 _, w
0 M; B/ z4 F, j) q( x0 v
2.as any other variable type是什么意思?* @+ d5 f& g- {5 o+ g+ D& e
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?$ j) A! {9 a! `" Z6 [
Example:
. l* C) `" Y" c% }6 Q4 F; Z- treenode current = rank(model(),3);& P Q) h9 z. L: u/ T. g
- pt(getname(current));
复制代码
/ }; M y8 C3 x0 ~' l" i% ^This sets the object that is ranked 3 in the model to current and prints its name to the output console. % T7 h4 ]; J3 i( B; z: H2 ]
8 ~3 s/ y( Z! I9 \5 S% X/ C" q3 x1 a& d; I
ownerobject(node thenode)
+ j* D0 v% o6 Y% E$ ? _) rDescription:
X& G* ~* @% ~, H* _7 m9 y9 sThis 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./ P# O& p, a9 A9 e3 l* m6 S
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 T W- v" E- \! Y该函数返回参数节点所在的实体。
3 p- M5 e3 j. X- R1 }. c9 K/ Y; ~5 H- C. g3 r7 g) w. q
Example:
5 O2 @) o& P# }" X# A- p- string objname = getname(ownerobject(c));
复制代码 ( O- ~- Y; P, [2 u) o
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);
复制代码 5 ~3 u, ]3 W3 w0 Z( O+ t8 Y
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
* r q0 ?, x# _( b" F这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。
/ f3 y$ F9 Q& {) |8 v$ n" C, Z" k% H% ]# e8 j, u- s" y$ I5 z3 E Y5 P
c<no parentheses>! z5 D7 w- A4 l/ F4 c
Description:
! s/ z6 {* ~& n, ?, aThis command is used to reference the active node during a function's execution.
& b" ~ J" b! V3 Z& QIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.
; N" ^ g C% m0 ^/ o& Y/ w" ~If the function is an event function, c returns a reference to the object that contains the event. 9 p- c, n! u) j" W
c在函数执行的过程中指向活动实体。- `5 e6 {! w) K3 z& N) W
如果是节点型函数,c指向函数所在实体,0 [% P' ]) p! d1 \4 c, x- y
如果是事件型函数,c指向事件所在实体。1 p" z' [6 U( V
Example: - treenode current = ownerobject(c);
复制代码
/ ]& _3 |% {, k: L# A7 c7 d% E1 m7 ]- N ?4 w4 J& L
setcurrent(thing)( w* v% h* }3 k# b0 ], ^7 S1 K8 ?1 [! \
Description: Deprecated. Do not use.
. N8 a, D/ I/ U0 P8 |0 LExample: /: D, d; \+ x) Y4 S5 _6 o5 P- \/ y
此命令不再使用。7 |& I- P& k: N5 |& [
6 w% _; E, t9 O
item<no parentheses> ' {, N1 E5 e" F, l0 F2 s
Description: . g1 D' G R- N& a$ r6 P1 V- b
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.
: x8 t5 G! q( F% U不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。* y0 z: y9 d/ ` m6 {* S
Example: - treenode item = rank(model(),3);- @1 z' P- W- G8 `7 E3 f! L( o
- pt(getname(item));
复制代码
& Y# x$ T) H& l2 U& |5 ]This sets the object that is ranked 3 in the model to item and prints its name to the output console.
% K6 G8 L1 |& s% j9 H: G2 m( o" A# G& @9 }
u! h3 v: T+ ^/ ssetitem(thing). q3 R, d6 z; S* j3 l9 f. o( t
Description: Deprecated. Do not use.
, z# G( m: D, ~( g s5 oExample: /! {2 W" \; z$ t2 J7 b3 q) X
此命令不再使用。
( D7 B, }/ G& l
6 G0 _" Q' i" i. Aparnode(num index)
( X! P0 U9 g% C* R }$ Z) tDescription: % A# ^' x* [4 q1 b, w
This command is used inside a function that is called by the nodefunction() command.. N2 I: l3 Q! i$ ?
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?$ m6 Z E( K8 d' O, Z3 Q' ?$ |
It returns the parameter passed to nodefunction specified by index as a node (or treenode). ! K C$ d5 R" k# {
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.9 {' q- {- _3 u' L0 X% o3 x
节点和树节点有何不同?% K* A) M1 G$ w: N g3 G
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc." r. b* c7 Y+ w1 T ^
parnode,parval,parstr这三个命令真是让人搞不懂啊...
9 J. E# x3 {- a) o; Z; ZParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 2 A0 |5 N, [& v/ d0 m& s1 \
Example: ( W* f# L' d7 ~, L
If a trigger/field is called with:
5 U& T j. r( R/ L0 Ynodefunction(thefuncnode, item)
5 s1 g) P$ o- o% f1 s! y/ y. Jthen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码
( W& ~/ u$ ~+ c+ z9 W. i8 W. r# o( `
port<no parentheses>) N8 Z9 S& C$ [5 E0 f3 H" I. z
Description: / {* h% e/ a2 M4 |$ B
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. ; F/ Q( V& I$ A. n( S: X6 I
Example: P$ p5 \- \* p+ r% b* H# m3 {% [
- int port = parval(3);) N8 ]/ B% W1 h1 L+ @+ i$ Y9 e7 S
- pd(port);
复制代码 3 j* E+ _. L) O; w4 c
This sets port to parval(3) and then prints the value to the output console.
7 {, f+ L( H4 y$ q! ], J
- J* Q$ c1 c% ]1 o4 c, p- ^不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|