question

Maryam H2 avatar image
0 Likes"
Maryam H2 asked Maryam H2 commented

Flexscript Error: syntax error, unexpected ':', expecting end of code

Beta 2022

Model_global_table_times.fsmVersion Beta 2022

Hello,

I've set a global table to be able to read specific times from there and do a calculation. The type of the cells are set as string in that column, but I am constantly getting this error:

syntax error, unexpected ':', expecting end of code

Could not finish parsing because of previous errors.

Can anyone help to solve this?

A snippet of the model is attached.


FlexSim 21.2.4
global tabletimetype of cell
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Felix Möhlmann avatar image
2 Likes"
Felix Möhlmann answered Maryam H2 commented

"executeCell()" interprets the content of the cell as FlexScript, leading to the error. And in your custom code you are trying to subtract two strings from each other (third column value). That is not a valid operation.

If you want to get a difference between two times of day, I'd suggest to use the Model.dateTime class.

https://docs.flexsim.com/en/21.2/Reference/CodingInFlexSim/FlexScriptAPIReference/Data/DateTime.html

The properties "hour", "minute", "second" and "millisecond" allow you convert the current time of day into a decimal number that can then be compared to a given time in the table.

For example, instead of 08:00:00, you simply write 8 (as a number) into the table.

Model.dateTime.hour + Model.dateTime.minute/60 + Model.dateTime.second/3600

will give you the current time of day (for example 8.607 for 08:36:25). Then you can get the time difference as 0.607 hours.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Maryam H2 avatar image Maryam H2 commented ·
@Felix Möhlmann Thanks for the answer!


If the time difference value leads to a negative value and I use that value in the "Delay" activity does the Delay activity take into account the negative values as 0?

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Maryam H2 commented ·

Yes, negative values will be treated as 0 in a delay activity. In other places (for example the quantity field of a "Create Tokens" activity) a negative value might lead to errors. To be save you can use "Math.max(value, 0)" to return 0 if the value is negative.

1 Like 1 ·
Maryam H2 avatar image Maryam H2 Felix Möhlmann commented ·
Got it, thanks!
0 Likes 0 ·