|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑 7 H! u( I8 B+ p2 c
4 U4 J' M$ c5 B7 Q4 B5 f1 _在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c); l5 u9 [4 K% z3 Z/ c* @0 k/ `% A" s
- treenode item = parnode(1);
1 F5 }, p' D. a- H' y0 S - int port = parval(2);
复制代码
2 y5 m: A! T$ ]4 U) X意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。/ V: t7 d9 j" z5 w
在接下来的代码中可以直接引用这三个已经声明好了的变量。1 {4 t8 \4 H9 d8 [
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
N0 b- f4 ~) e; ]/ O下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。
; y1 r0 ?3 V4 S3 ^. d3 F& J; a) L2 [ l1 j) R
treenode
' p; P2 e5 r# U- S9 `; s hVariable Types
+ Z7 ~ i3 J0 O8 E/ v* _0 s3 I) FFlexsim 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.2 V$ f P: C4 L: R* u/ b0 _/ y5 t
Type Description $ d S2 t- v/ d! {: E6 H
int integer type
- e$ b% b0 j. X# u- f" {5 G+ c) Mdouble double precision floating point type
- k5 ?0 S# _: F: E2 Hstring text string
' U# [- w5 q6 J, u. C. n4 ?% Jtreenode reference to a Flexsim node or object : N: T# S5 Z# j; r2 y& X" T4 ~
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。1 ?: q) Z& Q! @8 z; S; w
A8 u$ [& S5 N% u* M
current<no parentheses>
" \. N4 p) \, S0 dDescription:
2 J4 R* @6 ?. v5 n% c) X5 A8 HDeprecated. 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.
/ v! d7 y2 @1 o3 z* e不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。' n: q* u+ A3 u- f& _ X0 \
不解:1 y: s6 r7 C* G/ B% e, T
1.used...with....是什么意思?8 s2 s$ ^1 }5 p0 x# ?: ], f) H' j
以前current是必须和setcurrent一起使用的吗?
( V- y9 A" w* \8 k, i6 H& d: _7 N0 y' @; C+ m
2.as any other variable type是什么意思?! P/ K5 k" U$ O3 l0 W
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?! O. X7 h; h/ \2 Z8 A) B
Example:
6 x7 a. n0 w$ q5 [, }. C7 b- treenode current = rank(model(),3);; ^+ T2 C" A3 G; r$ g/ v
- pt(getname(current));
复制代码 3 i5 C4 o5 u) s+ _1 \! s$ z
This sets the object that is ranked 3 in the model to current and prints its name to the output console. 1 K$ ?. D, H3 D" a* G; E2 v0 s& r
, Q4 v2 X" B& D( q; X: C* v2 c' e
ownerobject(node thenode) t& O) @$ A4 T& f( N3 L+ |* |
Description:
( d* ~; { C6 O, f2 c% C1 H4 ZThis 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.7 ?9 ^5 O/ u6 u8 Q0 S0 Q- L
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.& k! ?' @% t% \ ]8 P
该函数返回参数节点所在的实体。
# u. K% k, q5 ~: B, h
4 d% O3 p& W$ [9 A% \Example:
) F' W% h$ o# l: V- string objname = getname(ownerobject(c));
复制代码
9 ~% s2 r4 h7 m8 v \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 g( s u# S9 u& f% ~" _+ x
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.% U6 j% f& ^5 N3 H
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。$ o7 y% F7 S% ~, o
9 \" k5 K3 e# h3 f9 H2 g5 l9 {, r5 L7 Q
c<no parentheses>( z- `# o# E) _
Description: & z- _1 I9 [* i" B- f" k6 V' ]
This command is used to reference the active node during a function's execution.
5 U- M, i$ @ YIf the function was called using nodefunction(), c returns a reference to the node on which the function is written.) y5 v$ R( S' [
If the function is an event function, c returns a reference to the object that contains the event.
* G& H! [9 ~9 g4 Y ec在函数执行的过程中指向活动实体。
7 F- Q! d+ I8 N$ U- ?如果是节点型函数,c指向函数所在实体,
; ^+ t2 `* r) F如果是事件型函数,c指向事件所在实体。: i7 ^# O3 L5 g9 o) T
Example: - treenode current = ownerobject(c);
复制代码 ' ]$ O, B3 h9 U# l$ B
# x6 G# U G% b5 ]
setcurrent(thing)
3 [. g! U% {& v: f- v* K# V# uDescription: Deprecated. Do not use.
( ^* j3 B& X% j0 A) O. A9 Z: L2 |Example: /
5 R% n/ _# ~& u7 U7 I此命令不再使用。
9 u3 ]) I G( h, \2 i. i. ?2 H$ l' E3 U6 a
item<no parentheses> ! J5 H5 T" |5 r+ _- r* \( x
Description: + r. N. G( | V7 a6 j @
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.
. A1 |7 I& K% Z6 N9 @% Y5 J2 G不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。# ]: Z% t% l& j! z: k, c1 V) k( R
Example: - treenode item = rank(model(),3);7 ^6 ~, b( u7 D, B0 k9 X+ ^4 Q% _8 f& x
- pt(getname(item));
复制代码
: `4 @& k0 ^" Q5 ]3 k2 `4 n6 K0 vThis sets the object that is ranked 3 in the model to item and prints its name to the output console. ; Q0 } j5 j6 z# j" P3 G
4 W) A' {/ q% x1 w( A+ V" e4 \, U8 B
- D! i) g& m* a6 bsetitem(thing)- R: V0 M. K! d' Q# r! @
Description: Deprecated. Do not use.
- b( }! G7 y& R2 ]% S/ _Example: /& k* H1 @2 z4 ~/ V7 S
此命令不再使用。' X; G8 h& ]2 v3 T
! ^6 O2 y( R5 tparnode(num index) $ Q7 q' M* B! a" c& B% M" r" z
Description:
( y5 O7 k4 |# e8 A6 J) J) fThis command is used inside a function that is called by the nodefunction() command.
; S ]3 d; d: U& u' N* Q1 b/ @: i此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
3 L2 M. v6 g( U# g8 \6 M" TIt returns the parameter passed to nodefunction specified by index as a node (or treenode).
# [9 q; Z2 f' T此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction. h- G& k6 P& u6 b$ g7 ]" g- G
节点和树节点有何不同?
9 q6 i5 Q d: V5 EThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
! R6 j+ m. P1 g5 Yparnode,parval,parstr这三个命令真是让人搞不懂啊...
. O; ?6 H+ J( s+ GParameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. ( Q3 N0 l% j9 x1 g2 [! j
Example: 2 Q2 }% [" u% @, a# d
If a trigger/field is called with: 7 k4 w( \) t& o" o3 `' I4 }
nodefunction(thefuncnode, item)
2 S5 e$ d& \2 H# c+ x" b$ Hthen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:- treenode item = parnode(1);
复制代码
% {( e8 m* r6 P& |) N
0 K7 @: i6 ?! |- Q8 @3 u4 Qport<no parentheses>6 \! e7 N. F% M
Description: 9 u9 k. E; |: B2 A% O9 B2 E- 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. ' z8 i' R0 ]- u6 L- L1 L7 Y
Example:
8 t( b t5 a4 G3 R- J5 j, @2 r- int port = parval(3);; l, \8 G% j. [* _
- pd(port);
复制代码
+ J" S: k1 {+ ~- y9 j0 ^% X9 BThis sets port to parval(3) and then prints the value to the output console.
: f+ J( l1 F: o2 G" J$ S4 M( |
7 d* c( E. _5 e; d6 v5 m不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|