# Function MID in URScript

**URL:** <https://forum.universal-robots.com/t/function-mid-in-urscript/21012>\
**Category:** URScript\
**Created:** [May 2, 2022, 2:36pm UTC](https://forum.universal-robots.com/t/function-mid-in-urscript/21012 "2022-05-02T14:36:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon36598866](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@anon36598866](https://forum.universal-robots.com/u/anon36598866)\
**Post date:** [May 2, 2022, 2:36pm UTC](https://forum.universal-robots.com/t/function-mid-in-urscript/21012/1 "2022-05-02T14:36:26Z")

</div>

Hi,

I trying to do a URScript, and i have to use the function “MID”, at most of the programming languages there is function like that, but in Urscript im not finding. Anyone knows how can i find a function like this in URScript? Thank you.

Best regards.

---

<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:** [May 2, 2022, 4:10pm UTC](https://forum.universal-robots.com/t/function-mid-in-urscript/21012/2 "2022-05-02T16:10:33Z")

</div>

What is your expected behavior for a MID function? Are you trying to find a midpoint between 2 Waypoints? The middle of 2 numbers? The median of a statistical dataset? You can write and define your own functions as you need using UR script. See my post below for an example of a script that finds the midpoint between 2 Waypoints:

> [@Move TCP to Midpoint Between Two Contact Points](https://forum.universal-robots.com/t/move-tcp-to-midpoint-between-two-contact-points/20601/2):
>
> Script: def midpoint(first, second): mid = get\_actual\_tcp\_pose() mid[0] = (first[0] + second[0]) / 2 mid[1] = (first[1] + second[1]) / 2 mid[2] = (first[2] + second[2]) / 2 return mid end Add a script file into your before start sequence and type in/paste that into it. Then use an Assignment node to store the points after contact, and use another Assignment node to call the script and pass in the 2 stored points. You can use this newly assigned Midpoint just like any other waypoin…
