# IfNode "check expression continuously" missing in SDK

**URL:** https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806
**Category:** URCap Development
**Created:** [September 25, 2018, 11:45pm UTC](https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806 "2018-09-25T23:45:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![anon80493405](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@anon80493405](https://forum.universal-robots.com/u/anon80493405)
#### Post date: [September 25, 2018, 11:45pm UTC](https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806/1 "2018-09-25T23:45:58Z")

</div>

Hi,

I’m trying to create an IfNode that checks an expression continuously.  
In Polyscope this is done by clicking the “check expression continuously” checkbox.  
I’ve noticed there is no way of setting this checkbox/setting in the SDK - you can only simply create an IfNode with an expression.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/230a46045317c1ce74f9d1dcd6979bd76f633fc1.png)

When comparing this to the LoopNode, a LoopNode has a ConfigFactory used to set the configuration of the LoopNode.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/6804e600e538b288b13bbf24dde724e32eb55e78.png)  
The LoopNodeConfigFactory has a method to create a LoopNode with an Expression and a Bool which enables the “check expression continuously” checkbox on the LoopNode in Polyscope.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/946d8e4863314a3ee761d8200de4044d8372a2a6.png)

Is it possible to somehow enable the “check expression continuously” checkbox of an IfNode pragmatically? Or is there a recommended work around for this?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![anon65613222](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@anon65613222](https://forum.universal-robots.com/u/anon65613222)
#### Post date: [September 26, 2018, 6:00am UTC](https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806/2 "2018-09-26T06:00:21Z")

</div>

This is how it looks in the URscript code when checking the box in PolyScope.  
So basically it starts the if in a thread, and the program loops the check with the `while` and checking if it is true as long as the thread is not done and if it is not true meanwhile, kill the thread.  
Would be nice to have the same as the LoopNode, but meanwhile I guess you could just set it up the same?

```auto
while (True):
   $ 1 "Robot Program"
   $ 2 "If True "
   global thread_flag_2=0
   thread Thread_if_2():
     # Just a Popup as a holder for whatever the if should do.
     $ 3 "Popup"
     popup("Insert your code here", "Warning", True, False, blocking=True)
     thread_flag_2 = 1
   end
   if ( True ):
     global thread_handler_2=run Thread_if_2()
     while (thread_flag_2 == 0):
       if not( True ):
         kill thread_handler_2
         thread_flag_2 = 2
       else:
         sync()
       end
     end
   else:
     thread_flag_2 = 2
   end
 end

```

---

<div class="post-metadata">

### Author: ![anon80493405](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@anon80493405](https://forum.universal-robots.com/u/anon80493405)
#### Post date: [September 27, 2018, 5:56am UTC](https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806/3 "2018-09-27T05:56:15Z")

</div>

Thanks for the quick reply Rasmus,

This is perfect and works in the case where all your code/nodes are known at the time of writing, however I’m trying to add child nodes (waypoints) dynamically or at run time to this IfNode’s rootTreeNode.

Essentially, I want to monitor an input for the duration of a group of movements, if the input switches at any point during these movements, the movements will cease. I have got this working with custom scripts and the IfNode’s “check continuously” checkbox/function within Polyscope, however I want to abstract the complicated script code from the user.

I’ve tested this using a custom node, where I’ve written a similar script node to the one you provided into the `ProcessActive` node’s `generateScript()` function.  
ProcessActive node also generates the Move and Waypoint nodes (from my `createSubtree()` method) as so:

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/9d51ab579d68ee3b2dca0fa0759ddb010760cec5.png)

When running the program, it never actually got to the Move and Waypoint nodes, they were skipped every time. However it did toggle DO0 OFF when DI0 was ON.  
I then saved the program and checked the script file, an excerpt of the code is copied below.  
Note that there is no move or Waypoint nodes as there was in the program tree above.

```
        $ 3 "Process Active"
    	def Process_Active():
    		  if (get_digital_in(0) == True):
    			  set_digital_out(0,False)
    			  sleep(0.5)
    			  return False
    		  end
    		  return True
    	end
    	global thread_flag_2=0
    	thread Thread_if_2():
    		thread_flag_2 = 1
    	end
    	if (Process_Active()):
    		global thread_handler_2=run Thread_if_2()
    		while (thread_flag_2 == 0):
    			if not(Process_Active()):
    				kill thread_handler_2
    				thread_flag_2 = 2
    			else:
    				sync()
    			end
    		end
    	else:
    		thread_flag_2 = 2
    	end
   # end: URCap Program Node

```

My conclusions from testing this method are that: I still have the problem that my `ProcessActive` parent node cannot “continuously check” the `ProcessActive()` script function whilst executing its child nodes, as the child nodes in this case have not actually shown up in the script code - which I find odd in itself (They do show up in the “program.txt” file though).

---

<div class="post-metadata">

### Author: ![anon80493405](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@anon80493405](https://forum.universal-robots.com/u/anon80493405)
#### Post date: [October 1, 2018, 3:37am UTC](https://forum.universal-robots.com/t/ifnode-check-expression-continuously-missing-in-sdk/2806/4 "2018-10-01T03:37:15Z")

</div>

I finally have it working and have figured out what I was doing wrong in the above reply.

Because the script is called in the `GenerateScript` method of my ProgramNode (Java) code, I forgot to add the `writer.writeChildren();` call where I wanted my child nodes to actually execute.

Doing this, my program executes all child nodes in the ProcessActive node whilst simultaneously checking the state of DI0 throughout the process. The execution of child nodes is done at run time so that a user can modify the subtree and add any child nodes they like - the program will still monitor whilst executing them.
