# FunctionModel - Using Variables

**URL:** <https://forum.universal-robots.com/t/functionmodel-using-variables/4763>\
**Category:** Java\
**Created:** [July 18, 2019, 6:59pm UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763 "2019-07-18T18:59:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman.reiner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roman.reiner/32/1294_2.png) [@roman.reiner](https://forum.universal-robots.com/u/roman.reiner)\
**Post date:** [July 18, 2019, 6:59pm UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763/1 "2019-07-18T18:59:11Z")

</div>

Hello,

When using the function model, adding functions I understand how to add variables to the function, but how do I use that variable in write script?

Function in function drop down with variables ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/0/034281056df1db241685f894f0599a8604e95960.png)

For example I am creating a function that uses an IP address, I add the function with the address variable and write this in the generateScript section.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/a/a4a587aa7713a88b63986f451149c6e4039427cd.png)

In runtime I get an error, it seems like it doesn’t recongize p1 variable (which is the address). What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![thph](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@thph](https://forum.universal-robots.com/u/thph)\
**Post date:** [July 22, 2019, 10:01am UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763/3 "2019-07-22T10:01:48Z")

</div>

Have you defined/instantiate your variable p1 anywhere?

---

<div class="post-metadata">

**Author:** ![roman.reiner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roman.reiner/32/1294_2.png) [@roman.reiner](https://forum.universal-robots.com/u/roman.reiner)\
**Post date:** [July 22, 2019, 11:33am UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763/4 "2019-07-22T11:33:48Z")

</div>

I am using the FunctionModel example to help out, it does this.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/8/8d83965cd7b93b29904debcd37ca96a339a1c7c0.png)  
When the function is called p1 is given a value, do I have to define this else where?

---

<div class="post-metadata">

**Author:** ![thph](https://avatars.discourse-cdn.com/v4/letter/t/b77776/32.png) [@thph](https://forum.universal-robots.com/u/thph)\
**Post date:** [July 22, 2019, 12:01pm UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763/5 "2019-07-22T12:01:06Z")

</div>

No, sorry I thought you were using it in another context. Anyway, if you follow this sample there should not be any problem. Could you show the error that you are getting?

---

<div class="post-metadata">

**Author:** ![roman.reiner](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roman.reiner/32/1294_2.png) [@roman.reiner](https://forum.universal-robots.com/u/roman.reiner)\
**Post date:** [July 22, 2019, 12:12pm UTC](https://forum.universal-robots.com/t/functionmodel-using-variables/4763/6 "2019-07-22T12:12:42Z")

</div>

I just figured it out. Was missing a bracket at the end of a long array variable. I thought it had something to do with that p1 variable from this error message

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/7/7523e0a6292f74a967d88acd1896f2ee5531eb1e.png) but the error was caused by the line above the highlighted because it was missing a bracket at the end. 🤦‍♂️
