|
本帖最后由 zorsite 于 2013-9-12 20:14 编辑
% N; b7 z) p0 U: h. o3 d* }
- `( [; o Q, p2 X在触发器中常会看到顶端已经自动写好的一些代码,通常如下: - treenode current = ownerobject(c);8 Y N) U" ^% I' u _* d
- treenode item = parnode(1);, d$ O/ u t# Z( q6 x
- int port = parval(2);
复制代码
+ ]. k1 V7 U( G1 P2 v: `+ Q ]意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
2 Y" e$ {0 K' a& L6 x% B. f在接下来的代码中可以直接引用这三个已经声明好了的变量。
$ C+ L5 t1 u0 S# z# S9 L对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
3 z% q2 g' s, X7 ?6 Z# z下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。* x9 n7 X: g8 o% W
* T" W( W4 j% c x. Streenode
% m' {. B6 F, bVariable Types" I4 U* N2 U( ?0 w# M6 p9 E) }: x
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.) w$ j/ a( y& @% k
Type Description
7 ^$ e% l/ L3 R5 p! E7 _2 e2 I, \: hint integer type / K0 u4 g8 `( Q! G4 ] X
double double precision floating point type ' g* g* C- \! a+ y! X
string text string
0 O7 @: p |# Ntreenode reference to a Flexsim node or object
( Y1 `* t6 ]/ wflexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。+ y$ U: {2 E9 f' G9 I3 l
9 o' o2 W$ f' ~) T* T4 G9 o* V* b5 t
current<no parentheses> % \- a) V; d( e8 y3 O1 c4 P
Description: 6 V; M( A' G3 L
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.
0 s: W {' @( K5 N8 | x不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。 u( W' b% c! J0 x
不解:
; |" z$ f5 A5 `) h1.used...with....是什么意思?
% H2 N6 ^/ e7 F# q( c& r以前current是必须和setcurrent一起使用的吗?5 @* Y& a7 ]' f% [- ]0 D9 w
# x& B2 t f7 a9 ]% |2.as any other variable type是什么意思?# m b: v" I7 p2 s* n+ b* r A$ E
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?8 w" S4 z1 M: E
Example:
+ |2 C2 V ~- x/ V- treenode current = rank(model(),3);- ~7 y, x% c; P+ }5 W
- pt(getname(current));
复制代码
9 }, ]( [" _6 I" t9 t3 QThis sets the object that is ranked 3 in the model to current and prints its name to the output console.
% S! j& X- Z: g6 F4 {/ O/ {9 I3 S1 f B
5 \8 k) p4 L% U6 o: R
1 g9 k3 @% W5 j1 Sownerobject(node thenode)6 o, h6 v4 @0 g- j9 g
Description:
. r" z# L9 e$ Y; r, jThis 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., `' {3 N" R* j5 p% r" S' r
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.+ c% u, j* t6 X5 _7 x5 D+ g5 M- K I
该函数返回参数节点所在的实体。
1 U" R0 \! h0 R2 G
( Y/ a/ v' o" @Example: [( {. H6 R& q4 r# m
- string objname = getname(ownerobject(c));
复制代码
& H' C% m1 d# e* Q0 K, U bThis 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 y! {! O2 J/ Y& S+ n! p0 M; R! i }9 C
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
7 Q6 W# e Z6 `8 Q j这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。# r0 D6 p+ k/ H$ ~/ `* U
$ O% z9 [: e3 J0 t8 R& V6 u- xc<no parentheses>0 t- n+ T. M0 u6 F& _" n9 f
Description:
' b3 i: e) N' P; W$ K ?1 uThis command is used to reference the active node during a function's execution. ! x# p" D4 U$ q# O; V
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
R1 l$ m } E/ V- }# d: UIf the function is an event function, c returns a reference to the object that contains the event.
& M B$ m8 E5 n0 {$ C6 zc在函数执行的过程中指向活动实体。
& Y0 C' y6 V/ @* q如果是节点型函数,c指向函数所在实体,5 d; U9 Y3 V9 }1 h
如果是事件型函数,c指向事件所在实体。
! G- X: X7 n( H2 q& |# o+ a8 @Example: - treenode current = ownerobject(c);
复制代码
3 ]9 L* e; q+ D" ]' W3 J; U' t( a! }) ]; U: N
setcurrent(thing)' |. m' _. n4 G$ Z6 D: U$ t% h
Description: Deprecated. Do not use.
, m3 u; n. Q& S3 Y/ N% \Example: /
4 `( [9 X/ Z* H b4 X此命令不再使用。3 Y! A3 |% o3 { Z; q. d; Y
/ E5 f1 T6 i6 k
item<no parentheses> 1 }* Y% V3 h7 p* a9 A' A
Description:
3 P- J, p: I( i, ]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. ) J1 m& s1 A: s- k X% o
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。
+ G% B- b! l$ x$ ]Example: - treenode item = rank(model(),3);
1 @' A$ ?4 u, I5 N$ W9 d# @3 p0 x! i4 ~/ c - pt(getname(item));
复制代码
( I& I' e! S& ]& `This sets the object that is ranked 3 in the model to item and prints its name to the output console.
: }- U; e/ C8 S- N3 ^
9 m0 z& P3 p, k& i* `. A; _' }6 {( f2 Y" ~+ c$ o# E3 _$ F
setitem(thing)
7 `, [/ e+ a( |Description: Deprecated. Do not use. . A) w4 F) _: Q5 ^1 X; v
Example: /
; v# ?, A& I6 h此命令不再使用。! L9 M; `8 a1 r# u8 z' b( U
/ b5 r& A% {2 o" d8 U" J% x% X9 p1 Vparnode(num index) 0 P3 J% b4 d5 U( v. U
Description:
# q+ E8 @: l% K1 v' ]# UThis command is used inside a function that is called by the nodefunction() command.
4 ~ a8 ?0 L! N6 Q; P& h此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?
0 k/ [' f& O# c+ l9 Z( {$ lIt returns the parameter passed to nodefunction specified by index as a node (or treenode). ! h) \2 ~# D [7 X
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.% b5 }% r$ [9 Z
节点和树节点有何不同?
1 Q9 a9 H# n/ l* {' B! RThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.4 J* f4 t8 a' _. Q/ ^0 h" {
parnode,parval,parstr这三个命令真是让人搞不懂啊.... r2 L s% Q& a
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 8 e/ a0 G7 n( `! w% U* N. s
Example: & j! h3 F) I4 ?
If a trigger/field is called with: ! C7 J+ s% C: t- }+ \. [; L5 h/ c0 e
nodefunction(thefuncnode, item) m) I+ h: U! d3 Z, Y! n1 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);
复制代码 " W' B$ `) D# c+ p) u- Z5 i! X! E
5 o* V7 R5 E* ?port<no parentheses># o G9 g( y: ~9 [6 e
Description: & Q n3 R* H$ m( }
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.
, M% c% c% X% ?Example:: M% R/ S% T( t0 ~. H
- int port = parval(3);
: z! D4 l# }/ a6 J- C; U$ b - pd(port);
复制代码
0 W9 s) Q R' Q6 a+ bThis sets port to parval(3) and then prints the value to the output console.$ d% G6 x1 U$ q- L1 P5 N# m7 p
3 {8 p& _/ ^: x0 [0 Q! L& b8 y不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。 |
|