# generateScript method called twice for the same ProgramNodeContribution

**URL:** <https://forum.universal-robots.com/t/generatescript-method-called-twice-for-the-same-programnodecontribution/1582>\
**Category:** URCap Development\
**Tags:** generate-script\
**Created:** [February 5, 2018, 2:27pm UTC](https://forum.universal-robots.com/t/generatescript-method-called-twice-for-the-same-programnodecontribution/1582 "2018-02-05T14:27:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon16416181](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon16416181](https://forum.universal-robots.com/u/anon16416181)\
**Post date:** [February 5, 2018, 2:27pm UTC](https://forum.universal-robots.com/t/generatescript-method-called-twice-for-the-same-programnodecontribution/1582/1 "2018-02-05T14:27:56Z")

</div>

Hi everyone!

I’m trying Polyscope 3.5.1 and I found out that `generateScript` method was called twice when playing a robot program for the same `ProgramNodeContribution`, generating an exception in my code (which assumes that the method is only called once).

This doesn’t happen every time I play a robot program (in fact it only happened once so far).  
I know that this is effectively happening because every `ProgramNodeContribution` has a static integer assigned when it is created, and on `generateScript` method, I log `Generating scripts for instance X`. So when I pressed ‘play’ this is what I got:

```auto
Generating scripts for instance 1
Generating scripts for instance 1
Generating scripts for instance 2
Generating scripts for instance 2

```

I have played/ saved many robot programs in Polyscope 3.4 and I never saw anything like this. Is this by any chance a known issue for Polyscope 3.5? Any ideas?

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [February 5, 2018, 3:01pm UTC](https://forum.universal-robots.com/t/generatescript-method-called-twice-for-the-same-programnodecontribution/1582/2 "2018-02-05T15:01:07Z")

</div>

In general, the code should be able to handle multiple calls to the `generateScript` method.  
It can be called when program is saved, or typically when the program is played.  
At play instance, it could happen, if the user double-taps (debounce) on the Play button.

Note: generateScript is only called, when all nodes in a program context return true on their respective `isDefined` calls.

---

<div class="post-metadata">

**Author:** ![anon16416181](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon16416181](https://forum.universal-robots.com/u/anon16416181)\
**Post date:** [February 5, 2018, 4:36pm UTC](https://forum.universal-robots.com/t/generatescript-method-called-twice-for-the-same-programnodecontribution/1582/3 "2018-02-05T16:36:54Z")

</div>

Thanks for your reply!  
Just to clarify, usually when I tap “play”, Polyscope calls `generateScript` once per node, one after the other. So for example if I have 3 nodes, I get

```auto
Node 1 called
Node 2 called
Node 3 called

```

And if I tap twice (really fast), I usually get:

```auto
Node 1 called
Node 2 called
Node 3 called
Node 1 called
Node 2 called
Node 3 called

```

The situation described above is exceptional and that’s why I thought about posting it here. So can it be that `generateScript` is called twice for the same node when pressing `play` only once?
