treenode current = ownerobject(c); & s L+ }! h( m. n: q
treenode item = parnode(1);) x3 z( p# G) M
int port = parval(2);
复制代码
/ e( T1 M+ o! G0 J; a5 m意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。. P; [7 A1 t# M% x
在接下来的代码中可以直接引用这三个已经声明好了的变量。' \% R$ b) b, |5 l' Z# T) s- q
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。1 i" R" l7 e: ^# K! v
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。# D/ M5 U4 J& a' ?) H% O3 p
6 g( Z0 l1 q6 o1 z5 i$ B& `
treenode& G9 d! v' g( p' h. \( v
Variable Types; {: _# q: N3 l; m$ i i# d9 @
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. / K+ B% E8 }) t+ C. |# i& EType Description 9 T) M8 v n7 c
int integer type - N/ ]0 x' M, \5 m Edouble double precision floating point type . S& G# X0 D- e- _+ a
string text string 4 V- G" _ V0 p# C8 \
treenode reference to a Flexsim node or object ) x b$ o" ]+ W$ K) F. Z
flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。( F( n' _2 R. Z
1 h) I. H# S( T g/ `' M
current<no parentheses> . H$ E8 r! R9 o/ O8 i& g; Y8 x
Description: 5 ]' R" b. C7 C
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. ( r8 e3 h; l1 J4 ~1 |不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。% p9 o4 a$ h a' U9 ]
不解: : A/ \3 I; e1 k, ~1.used...with....是什么意思?) W' b' f: J9 `
以前current是必须和setcurrent一起使用的吗?! T% _# J' J3 j1 Q# c
! U" s9 W. |: k# K
2.as any other variable type是什么意思? % c5 E# h. J2 [" T; N+ M前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?8 J: _1 a8 ]9 ]/ P+ i
Example: ; B" m( H3 D, K4 D! T
treenode current = rank(model(),3);: |" l+ T1 c- q) v D2 k
pt(getname(current));
复制代码
9 i/ ]; f. S. q: B0 A/ _
This sets the object that is ranked 3 in the model to current and prints its name to the output console. - X% g( u' i* _! r( }, q
% p4 @( \6 e+ U- }
* m" e- X- z* X0 N* S7 T( ?: \ownerobject(node thenode) % r* u9 U5 y- b8 f+ X) Y. iDescription:+ U2 D7 ?9 }* }+ H9 s( B5 W
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. ( } F% N2 V% n+ I8 }0 w/ c8 jThis 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. * J5 n) v" @2 N0 Z' g该函数返回参数节点所在的实体。, l) F8 O8 P9 Q, u/ z
$ O0 a% N5 ~% @0 R$ Q- F- A. 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);
复制代码
& ?% _" L8 K9 T8 h3 XThis example is present in most code fields in Flexsim, and retrieves access to the "current" object.3 J% P) ~: }8 A' ?# w; q0 p
这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。 7 K% m& H9 a6 j 6 X1 T) l: L+ D8 h" Pc<no parentheses>! P+ F$ k8 X! ^- k
Description: $ ^& ^, s4 m* W
This command is used to reference the active node during a function's execution. 2 O- B" v( i" e+ f
If the function was called using nodefunction(), c returns a reference to the node on which the function is written. # n$ i' j) o& X. K" ~If the function is an event function, c returns a reference to the object that contains the event. : d6 T3 c: i9 c) o; D3 \ h! M
c在函数执行的过程中指向活动实体。 % ]: s1 k v2 d' D2 @, o如果是节点型函数,c指向函数所在实体,, I; p2 w! D- u( ~% Y
如果是事件型函数,c指向事件所在实体。. K5 }% a% K4 |5 ^8 k
Example:
treenode current = ownerobject(c);
复制代码
( h% I, t8 v9 o+ S s3 |- k2 h" o+ _, y1 w! \
setcurrent(thing)( O. ]$ _; C& D6 V+ x
Description: Deprecated. Do not use. . q6 {( K+ J: R4 v, P ^ E
Example: / & f+ N; l# K e5 `此命令不再使用。 : `! G1 A) {- ~ 7 O* H u# J) Z3 l/ H# v6 Ditem<no parentheses> / d% C `) x4 h; }' HDescription: ' x1 k! A* l# G8 p0 B- UDeprecated. 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. $ O8 G, u X4 l2 ]2 t: Z' w
不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。 2 M2 Y t6 S* S, E c: }- DExample:
- {; u7 a/ p& q4 rThis sets the object that is ranked 3 in the model to item and prints its name to the output console. ' H. i/ \( m% \# y' Y9 M, s8 w
; V& Z$ S' r7 B/ x" E, i4 P: d% ^2 k; s3 k
setitem(thing)$ u5 U2 M6 b5 F8 x7 [* g
Description: Deprecated. Do not use. 0 Q( Q% U0 J8 j7 ]
Example: / * s* G0 w: k( w# o此命令不再使用。2 q% X% [/ ^2 G3 m" J- M+ Y$ k
: k0 b5 f' ~3 W' K) Lparnode(num index) 5 G3 m! N# o/ z0 W$ ?- n+ p
Description: 0 x1 B' J- X9 T+ d7 w% f
This command is used inside a function that is called by the nodefunction() command.+ M6 M5 N0 w- v8 f/ R
此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?* |+ z+ q; Q. G( v
It returns the parameter passed to nodefunction specified by index as a node (or treenode). ( F% v) m X& h. a! c
此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction. q" ?1 @ R5 E节点和树节点有何不同? . x+ K; K; Z* F2 ^4 n5 n6 Y3 UThe first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc. 2 V. p* |( @2 t0 D1 }parnode,parval,parstr这三个命令真是让人搞不懂啊...1 d! I" B3 q3 }; ^7 W) c9 g" j
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively. 1 m. o3 ?8 u2 Q- z- N& wExample: 6 w1 X9 o) s- d; ? X$ B) o) bIf a trigger/field is called with: ; H; @8 |/ U! k+ gnodefunction(thefuncnode, item) 6 N7 N% g; x( h$ Qthen within the trigger/field, getting access to the item passed as the first additional parameter would be done with:
treenode item = parnode(1);
复制代码
& P* C! w% [' _ \# A
9 w8 ]2 P* P4 C- Q! x
port<no parentheses>- f5 g! X! T9 `: H
Description: / M4 d; i! r2 X" x, s6 L" J
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. 7 o( R; `) H5 o8 x$ d CExample: & n* |5 f5 `: j5 z" m
int port = parval(3); # G- h. B1 x$ H
pd(port);
复制代码
6 M2 W: F T6 X/ d0 q
This sets port to parval(3) and then prints the value to the output console., g5 g# I T* V, d, f& M- ~
1 V; x B- ?/ M2 L' X+ N4 h/ d
不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。作者: 天性518 时间: 2013-9-17 13:56 1#zorsite % T8 m9 F4 u, d/ r * R0 p* `3 |5 b& d ]4 M% C: q; N4 [/ F
首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。( u' x; C5 \. u; w, E! W2 c
首先在GUI中,它是这样的,如下图:[attach]1559[/attach]% `- M: u2 X3 _! i) a1 @
而在代码框中却是这样的,如下图:[attach]1560[/attach]作者: fl2014 时间: 2014-8-10 18:29
大神啊,解决了我多日的困惑作者: 1010265352 时间: 2014-8-11 13:56
额,很值得一看作者: 一骑绝尘 时间: 2014-8-20 10:01
C 一扫疑惑, 但parval(),parnode() 还是有点不解