Ankur A3 avatar image
Ankur A3 asked Jeanette F commented

How to provide delay while using flexscript code?

Hi Team,

I would like to know on how to provide delay while executing flexscript code.

For example:

1. Check Machine Availability?

2. Delay 5 mins

Repeat 1 & 2

Can you help me with the flexscript code for delay?

Thank you!

FlexSim 21.1.5
· 1
5 |100000

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

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Ankur A3, was Joerg Vogel's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
Joerg Vogel answered Jason Lightfoot commented

Discrete event simulation source code expects an immediate result or a new event. Because you want to delay a source code, then you do this by an event that execute the treenode 5 minutes later again. You can use a delayed message, a user event, a process time.
OR you do this in process flow which naturally supports delays of tokens!

· 9
5 |100000

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

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·

Just a quick note that from version 22.1 you can do this using coroutines where the syntax would be:

await Delay.minutes(5); 

...but since the OP is in 21.1 it doesn't apply.

Generally I'd avoid polling and instead detect the availability at the time it becomes available, and (if needed) then wait for the next poll time. This approach fits well with discrete event simulation where you try an model just the events that you need.

1 Like 1 ·
Ankur A3 avatar image Ankur A3 Jason Lightfoot ♦ commented ·

Hi Jason,

I do agree with the point on tracking the object until it becomes available but how can it be done while using source code in one of the object triggers.

Can you help me with it?

How can we write the condition to track multiple objects until it becomes available?

For eg:


How can we track the status of machine 1 or 2 using source code?

Thank you!

0 Likes 0 ·
1677484187874.png (4.1 KiB)
Ankur A3 avatar image Ankur A3 Ankur A3 commented ·
0 Likes 0 ·
Show more comments
Joerg Vogel avatar image Joerg Vogel commented ·
You may parse the node by c to execute it delayed again.
0 Likes 0 ·
Ankur A3 avatar image Ankur A3 commented ·

Hi @Joerg Vogel,

I agree with your point, but I am not able to use this using process flow.

I am using a code under fluid library object where I need to refill the object once its level gets down up to certain limit. Also, I need to first track the availability of other things before start refilling procedure. That's the reason I am thing to delay the code for the time when other equipments become available.


What will you prefer to use for delay in this case?

Thank you!

0 Likes 0 ·
1677484583820.png (61.3 KiB)
Joerg Vogel avatar image Joerg Vogel Ankur A3 commented ·
@Ankur A3, now that you describe a core purpose of your question of delaying a code execution, you can ask a question in a new thread! Delaying an activity until a condition matrix get fulfilled.
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Ankur A3 commented ·

You can still use Process Flow, by creating a token by code. The relevant methods can be seen for example when selecting to use a SubFlow in a fixed resource's transporter field.



To do everything in code you could

- write the time an equipment will be available again to a label on it, then use one of the methods described by Jason and Jörg to re-run the code at that time (of course only possible if the time when the objects becomes available can be known beforehand, so it might be difficult in a model with constand flow)

- build the logic "in reverse". Have the relevant equipment send a message to the tank whenever it becomes available. The passing mark code would set a label on the tank if the equipment is not available at that time, which then causes it to evaluate the refill code when it next receive a message.

0 Likes 0 ·
1677486116478.png (65.7 KiB)
1677486135646.png (5.0 KiB)
Joerg Vogel avatar image Joerg Vogel Ankur A3 commented ·

@Ankur A3, you can call from any source code editor from within source code a process flow by command. But you are not allowed to delay a process flow token advance progress.

You can think of reevaluating this source code trigger by run cycle event controlled in process flow. This flow object trigger checks only all necessary conditions.

0 Likes 0 ·