AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.

question

Kari Payton avatar image
1 Like"
Kari Payton asked Adrian Haws edited

How to use custom code to set operator state?

In my model, I acquired an operator, and next I want to set his/her state to busy. I tried using a custom code block but when I run the program the operator's state stays busy. I have tried changing the object reference but no luck.

FlexSim 16.1.0
process flowcustom codestatesutilize operatorfreeoperator
operatorstate.png (32.9 KiB)
· 2
5 |100000

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

@Kari Payton, you may need to clarify what is going on. It sounds like the code is doing what you want it to do - changing the state of the Operator to busy. Is the issue that the state stays as busy when you want it to change to something else?

0 Likes 0 ·

@Logan Gold I want it to say busy, but when i click on the operator it says idle.

0 Likes 0 ·
Dawid Dabal avatar image
3 Likes"
Dawid Dabal answered Dawid Dabal commented

In one of my models I used Custom Task =>TaskType Utilize and FreeOperator because I wasn't sure for how much time my operator is going to be busy. Maybe this could help.

· 8
5 |100000

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

Thanks David. That works. As a reference to others having this problem, I attached a snapshot of the "custom task" box. Also it is important to un-check "wait until complete" or the token will not be released.

A list of state numbers can be found here.

0 Likes 0 ·
operatorstate.png (30.1 KiB)

@Dawid Dabal How did you get your operator to do other things after you did the custom task to utilize? My token gets stuck when I tell it to travel after i set the custom task. Are all of your tasks custom? @Logan Gold

0 Likes 0 ·

If you have problem with Involved/Station fields you can free operator with Custom Code. You can manually destroy the Utilize task with a code:

destroyobject(first(node("{your operator adress}>variables/activetasksequence", model())));

0 Likes 0 ·

@Dawid Dabal I'm new to FlexSim how do I find the operator address?

0 Likes 0 ·
Show more comments
Matt Long avatar image
2 Likes"
Matt Long answered

Assuming your reference to the operator is correct, operator's state is being set to busy, but then he's being set back to idle most likely by his own internal mechanics. Objects do a lot of state changing on their own and setting an object's state only overrides their current state until the object changes it again. For instance, giving an operator any task will change its state.

This means you can either do what was suggested in the answer by @Dawid Dabal or you'll need to place Set Object State activities everywhere that the state gets changed in order to keep it in a busy state.

5 |100000

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

Steven Hamoen avatar image
1 Like"
Steven Hamoen answered

I have struggled with this also and tried exactly the same solution. I think that Brenton pointed me to a solution with using he TSDelay activity where you can set the state. Maybe this could be a solution for you as well.

5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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