How to provide delay while using flexscript code?

How to provide delay while using flexscript code?

rajankur6494
Collaborator Collaborator
615 Views
11 Replies
Message 1 of 12

How to provide delay while using flexscript code?

rajankur6494
Collaborator
Collaborator

[ FlexSim 21.1.5 ]

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!

0 Likes
Accepted solutions (1)
616 Views
11 Replies
Replies (11)
Message 2 of 12

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

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!

0 Likes
Message 3 of 12

joerg_vogel_HsH
Mentor
Mentor
You may parse the node by c to execute it delayed again.
0 Likes
Message 4 of 12

jason_lightfoot_adsk
Autodesk
Autodesk

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.

Message 5 of 12

rajankur6494
Collaborator
Collaborator

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:

1677484187874.png

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

Thank you!

0 Likes
Message 6 of 12

rajankur6494
Collaborator
Collaborator

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.

1677484583820.png


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

Thank you!


0 Likes
Message 7 of 12

rajankur6494
Collaborator
Collaborator
0 Likes
Message 8 of 12

joerg_vogel_HsH
Mentor
Mentor
@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
Message 9 of 12

moehlmann_fe
Advocate
Advocate

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.

1677486135646.png

1677486116478.png


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
Message 10 of 12

joerg_vogel_HsH
Mentor
Mentor

@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
Message 11 of 12

jason_lightfoot_adsk
Autodesk
Autodesk
I think 'source code' is a misnomer.

You can track the availability by listening to events in process flow - simple.

0 Likes
Message 12 of 12

Jeanette_Fullmer
Community Manager
Community Manager

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