# How to set robot program variable at runtime from URcap

**URL:** <https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630>\
**Category:** Java\
**Created:** [March 10, 2020, 2:20pm UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630 "2020-03-10T14:20:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon26309524](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@anon26309524](https://forum.universal-robots.com/u/anon26309524)\
**Post date:** [March 10, 2020, 2:20pm UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630/1 "2020-03-10T14:20:56Z")

</div>

Hello,

**TASK:**  
My task is to create a popup window with several input interactions (to make it more easy for the beginning, we can say they are some buttons)

After pushing a specific button, the already running robot program shall receive an information about that. After that, some different part in the robot program has to be executed.

I thought about a variable that is created and overwritten with the help of a urscript code on a button pressed event.

**PROBLEM**  
Via the generateScript function from the installationnode i created a variable, which will be overwritten from the generatescript form the programnodecontribution, whenever a button is pressed. Problem is that the generate Script from the programnodecontribution only will be executed on time after starting or saving the program.

Im pretty new in the URcap universe and i hope you guys can help me 🙂

---

<div class="post-metadata">

**Author:** ![anon21687472](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@anon21687472](https://forum.universal-robots.com/u/anon21687472)\
**Post date:** [March 10, 2020, 5:16pm UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630/2 "2020-03-10T17:16:27Z")

</div>

Hi,

I’m not sure if I understood your question, the generatescript in the program node contribution will execute every time that the program tree passes by the UR Cap node.

---

<div class="post-metadata">

**Author:** ![anon26309524](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@anon26309524](https://forum.universal-robots.com/u/anon26309524)\
**Post date:** [March 11, 2020, 7:15am UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630/3 "2020-03-11T07:15:27Z")

</div>

Ok, i added several nodes to be sure that the ur cap node is being executed. I also placed a println in the generateScript function (in ProgrammNodeContribution) to see when this function is called. But as is said it will only being executed when i restart the program or when i saved the program.

---

<div class="post-metadata">

**Author:** ![anon26309524](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@anon26309524](https://forum.universal-robots.com/u/anon26309524)\
**Post date:** [March 11, 2020, 8:41am UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630/4 "2020-03-11T08:41:56Z")

</div>

Is there another way other than the generateScript function to set a variable from URCap and returning it to the robot program while a program is running?

---

<div class="post-metadata">

**Author:** ![anon47761871](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anon47761871](https://forum.universal-robots.com/u/anon47761871)\
**Post date:** [March 13, 2020, 7:48pm UTC](https://forum.universal-robots.com/t/how-to-set-robot-program-variable-at-runtime-from-urcap/6630/5 "2020-03-13T19:48:16Z")

</div>

Have you seen the examples included in the SDK?

[https://plus.universal-robots.com/download-center/](https://plus.universal-robots.com/download-center/)

Cheers
