Notifications
Clear all

[Closed] Recursive functions to find property

How can I write a recursive function to find a specific property such as ‘bend’ and once I find the first instance of the property I return the value and stop searching. I’d be searching through a selection of nodes.

6 Replies
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Like this

fn findProperty node prop:#bend =
(
	local found = off, result
	for p in getPropNames node while found where (found = (p == prop)) do result = (getProperty node prop)
	result
)

does it really need both found and result?

2 Replies
(@gazybara)
Joined: 11 months ago

Posts: 0

We can utilisez node var

fn findProperty node prop:#bend = 
  (
  	 local found = off
  	 for p in getPropNames node while found where (found = (p == prop)) do node = (getProperty node prop) 
  	node
   )
(@denist)
Joined: 11 months ago

Posts: 0

this doesn’t work. absolutely. try again

Ok. You are right.

fn findProperty node prop:#bend = 
(
	local found = off
	for p in getPropNames node while found where (found = (p == prop)) do number = (getProperty node p) 
	number
)

Or slover solution

fn findProperty node prop:#bend = for p in getPropNames node where p == prop do exit with (getProperty node p) 

Denis what would you recommend?
I essentially need to find a specific property on a node and once I find that property I need to get its value.