全球FlexSim系统仿真中文论坛

搜索
查看: 72114|回复: 6
打印 上一主题 下一主题

Flexsim2017版FlexScript语法的重大改进

[复制链接]
跳转到指定楼层
1#
zorsite 发表于 2017-3-14 13:45:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zorsite 于 2017-5-11 08:27 编辑 ( g6 D$ G# X5 S7 t$ l; ?( x1 n/ l

" S6 b6 K' d! d: n2 P% t
The Big Benefits to Syntax Changes in FlexSim 2017

- c' m" J: N. F) u
Posted by Markus Cueva/ December 9, 2016/ Article
1 Z8 T5 K9 u& Q0 L( A
8 W% _, B4 V1 g
! _8 K& s: A; @6 P9 r7 C
4 n5 G- [2 a+ Q. ~7 s7 E" r9 K  t7 _
Let’s start with two important statements:
( d9 x0 ~% }' |; o
  • We’ve made an enormous, comprehensive update to our FlexScript language.
  • All FlexScript in models created prior to FlexSim 2017 will still execute just fine… as long as your script was correct in the first place!
Now that you’re aware of the update—and that fact that your pre-FlexSim 2017 models will still work—let’s dig a little deeper into the FlexScript syntax, something we refer to internally as “dot syntax.” We’ll cover how it works and the reasons why the change was made in the first place.
! W+ B) d- t( c- c: W
Dot syntax? What’s that?

$ J- F6 p. Y* c  w
In FlexSim 2017, scripting is more object-oriented than in previous versions, which makes the code more streamlined and intuitive. You used to define logic in FlexScript using a library of global commands; here’s what it looked like to get a label from a token in Process Flow:
/ `( t" C: c  p+ c
getlabel(getlabel(token, “item”), “weight”);
" J* l8 k4 N4 b! w5 c: y# x
Here’s what that looks like using dot syntax:
& M2 d+ ]! v' L( M2 {, `2 _
token.item.weight;
- w$ r% K3 ^3 Z7 d9 J2 E7 K
Little more streamlined, isn’t it? Dot syntax is focused on entities—most commonly item, token, and “current”—and they all have three important characteristics:
$ R* F! y3 v' C0 o
  • Properties, which is the data that controls aspects such as location, size, and color. Dot syntax lets you access this data.
  • Methods, which are commands that do something or change a property value (set speed, change location, etc.).
  • Labels, those dynamic, custom properties we all know and love.
So, when you see an expression written in FlexSim’s new dot syntax, it’s easy to interpret what it’s saying. The dot always means “access,” which allows you to access properties and methods associated with objects and variables. Take the following line as an example:

+ A' K2 J5 r7 w; x3 Z. w+ q  @/ J" R( E+ O
current.name.startsWith(“Processor”);
1 ?1 W9 |( D$ h5 Z& P4 w
In this example, “current” is a reference to a 3D object we’re currently working with. A dot signifies a property we’re trying to access: the object’s name. Another dot calls a method to check if that name starts with the string “Processor.”

6 J* }8 Z. a- v4 j
So why make this change? There are actually three critical benefits as a result of the dot syntax update.

$ D  K2 v) Q' g
Better, simpler scripting
( z! q$ M/ `: Y( }( Z
As you saw in the above example, dot syntax expressions have a logical structure that’s easier to follow. It also carries a few other benefits that should improve scripting in the future. One is that dot syntax is more dynamic. Labels, which change or may not even exist during portions of a model run, used to require special treatment. Now, dynamic properties like labels work just like methods and static properties.
4 S; o- h8 H! _# ]
Expressions like token.SomeLabel.AnotherLabel? They’re possible now.
5 d2 ]( x4 J' W4 w
The other benefit is that the management of properties and methods (versus the old commands) just got a lot less complicated. This could empower our amazing developers to add new methods more frequently, and methods overall will require less parameters.

5 M( m0 e- L/ g/ X" C' C
Simulation speed boost
; l1 H- N3 M( Y; i" B( j+ b
That’s right, simulation runs have the potential to go much faster, and it’s a direct result of the scripting update in FlexSim 2017.

/ l1 D8 i; s- H4 x* f; }: V1 A4 y
The reason?

/ d) Z* k( _( L
All FlexScript is now compiled to machine code and executed directly—avoiding needless interpretation makes things more efficient, leading to faster processing of simulation events.

/ A7 A" S! m! L5 p; E
The smartest Autocomplete yet
6 c- l! O, u1 u7 O1 u5 |& W2 Y7 D
Finally, this change has enabled us to make some huge improvements to our built-in Autocomplete, which now provides you with a list of properties and methods to access as soon as you type a dot. You’ll also be happy to know that the Autocomplete is a little more forgiving these days—even when you misspell or are just trying to get close to a name that’s on the tip of your tongue, the closest possible matches will still appear.
2 y2 ~2 U: `4 k6 L- w+ `* m4 \+ q; v
It’s also smarter than ever before. Have you already declared some labels? Autocomplete will show those if they come up in the context of what you’re trying to do.

+ b  C9 ~' h& A
We truly believe that this update is a big step forward to helping FlexSim become the best simulation software it can possible be. Remember that if you ever need help getting familiar with dot syntax, our support team and worldwide user base can be found on FlexSim Answers and would be more than happy to help.

9 q3 F! z* w' K) [5 a2 R- }* P" l1 k4 k; O7 B
2017版中对 FlexScript 语言做了大量改进。不用担心,以前的程序仍可正常运行。
1 V' ~; _/ x! }0 R- X
啥么是点语法
2 g7 D  O- T; q7 B! h4 N$ U6 s3 G
点语法面向对象,程序语句读起来更顺畅。
4 y& \5 A, u1 @: a
点语法聚焦于实体,比如current,item,token。这些实体都有3个重要特征:
7 I  ?0 C2 {: g0 J0 v
属性、方法、标签。

( Y. j) ?" i  D) H* t5 A
点的意思是连接到什么东西,比如连接到(实体的)属性,或者方法。比如:current.name.startsWith(“Processor”);

9 Y3 W8 e2 ^, b# Q.name是名称属性,.startswith是方法,判断(名字)是不是以(Processor)开
/ J) C9 g3 W/ L2 }
头。

* K7 v! c% [' r/ Y( u( i) ^/ @
点语法至少有3个好处。
. \0 ^; T3 N) _0 k% x2 s+ U# K
语言更简洁,效果更好

+ \9 Y8 Y3 Q) Q3 U$ o- N( {: J
点表达式更容易让人理解,而且动态效果更好。比如标签在模型运行的过程中会变化,甚至被删除,所以在写代码时经常要特别注意。但是现在有了点语法,处理起标签就简单多了,可以把动态标签当作静态属性来处理。
% q/ F# ^0 e# C1 j# d( Q+ {0 h7 L
用了点语法之后,对属性和方法的管理也更简单了,大家可以贡献更多的方法,而且方法对参数的需求也比旧式命令要少。
9 S" R( K* ~' I, o" a
速度更快

2 {: D; |8 M) m) h! N; V1 g8 `
自2017版起,FlexScript被编译为机器语言直接执行,大大提高了模型运行速度。
" A, `' i) v; T$ f- M
代码自动完成

- X' Z* F! x& i输入点号之后属性和方法就自动弹出来了,即使偶尔拼错了它也会帮你找到最匹配的那一个。  C4 {$ P$ q" Z& w( L( Y# v2 }* S

; L# P" A% d  ?5 D
. M9 u7 V& P" H9 w实在是编不下去了,其实我不懂罗马尼亚语……
2#
慧娴亚伦 发表于 2017-3-15 01:13:27 | 只看该作者

5 }4 n; |0 n- d$ E加老师编得很完整啊。
3#
liuzhifan 发表于 2017-3-15 03:16:42 | 只看该作者
正在学习代码
4#
eb_sun 发表于 2017-3-15 15:18:19 | 只看该作者
谢谢分享
5#
taiheilam2 发表于 2019-10-2 13:18:59 | 只看该作者
哪里可以学写flexscript 呢
6#
慧娴亚伦 发表于 2019-10-5 19:26:06 | 只看该作者
taiheilam2 发表于 2019-10-2 13:180 e5 B9 |1 D2 H
哪里可以学写flexscript 呢
+ o. Z( f& e& R% _; ^# g( y
腾讯课堂有flexsim代码的入门课程:7 `: ~9 d7 r2 F% D& W
https://ke.qq.com/course/273777?tuin=143fe19e
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|全球FlexSim系统仿真中文论坛 ( 京ICP备14043114号-2 )

GMT+8, 2024-4-19 22:15 , Processed in 0.071692 second(s), 13 queries .

Powered by Discuz! X3.3© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表