# Wait in script code error

**URL:** <https://forum.universal-robots.com/t/wait-in-script-code-error/24281>\
**Category:** Technical Questions\
**Created:** [October 6, 2022, 6:58pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281 "2022-10-06T18:58:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elettrotec\_AC14](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Elettrotec\_AC14](https://forum.universal-robots.com/u/Elettrotec_AC14)\
**Post date:** [October 6, 2022, 6:58pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/1 "2022-10-06T18:58:57Z")

</div>

Hello,  
i have a problem with this code:

def end\_mission(cons, end):  
end = True

wait cons == False

end = False  
end

the error is wait is not define…

how is possible??  
sorry for my english.

thank all

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [October 6, 2022, 7:06pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/2 "2022-10-06T19:06:52Z")

</div>

“Wait” is not a command in UR Script. The command for that is sleep. However, sleep looks for a number as an input, not a logical statement like true or false.

For you, you’d want something like:

while(cons != False): \<— This could also be written simply as “while(cons):”  
sync()  
end

---

<div class="post-metadata">

**Author:** ![Elettrotec\_AC14](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Elettrotec\_AC14](https://forum.universal-robots.com/u/Elettrotec_AC14)\
**Post date:** [October 6, 2022, 7:10pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/3 "2022-10-06T19:10:17Z")

</div>

thank you so much  
but  
what is sync()?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [October 6, 2022, 7:24pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/4 "2022-10-06T19:24:23Z")

</div>

sync() uses up the available time slice that the code has been given. When doing something like a while loop that does nothing, or a thread that doesn’t do much, you can run into faults that say “thread blah blah blah used too much time” or something similar. Generally, instead of actually doing nothing in your loop, you want to call the sync() command so keep the scheduling in order

---

<div class="post-metadata">

**Author:** ![Elettrotec\_AC14](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Elettrotec\_AC14](https://forum.universal-robots.com/u/Elettrotec_AC14)\
**Post date:** [October 6, 2022, 7:48pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/5 "2022-10-06T19:48:05Z")

</div>

So i can use sync() also in thread instead of wait some time?

And if i can use sync() in thead that read data from plc what is the refresh time.  
Is sense use sync in this case or not?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [October 6, 2022, 8:02pm UTC](https://forum.universal-robots.com/t/wait-in-script-code-error/24281/6 "2022-10-06T20:02:11Z")

</div>

Don’t get too hung up on sync(). It really has to do with how operating systems schedule tasks and allocate processor time to achieve them. I just put it in the example because I know from experience that without it, the robot will fault with a “used too much time” error, and throwing that sync() command in there fixes it. In general, if you have a looping thread, put a sync() at the end of it.

As for the thread and PLC, I’m not exactly sure what you’re asking. The robot controller runs at 500Hz. You’ll have to read your PLC documentation to find its scan rate. The sync() command is not doing the actual waiting. The “while(cons != false)” loop is what is doing the waiting. It’s doing nothing (ie waiting) until cons becomes true
