[Closed] Running functions from the Listener
Hello, Im almost embarassed, to ask this question…and maybe Im rushing my training, so Im overlooking obvious things…but
when I run this function in the Listener or Evaluate All in the script window, (taken from the WAD-O- tutorials):
[i]fn descendentsOf obj =
(
– if want parent object in the array returned use:
–local descendents = #(obj)
– if just want descendents in the array returned use:
local descendents = for child in obj.children collect child
local i=0
while (i+=1) <= descendents.count do
join descendents (for child in descendents.children collect child)
descendents
)
…I just get the notice the function was run in the Listener
descendentsOf()…
but it doesn t do anything or return any info that I can see to the object(s) I have selected…If I type in say getCurrentSelection() in the Listener, it at least prints out the names etc, of the objects. Ive tried various ways to get it to do something but it doesnt return anything or do snything…did I forget a step?
I havent seen much what to do at this point…Im not much of a programmer yet I know but I was hoping to tackle one issue at a time…thanks!
when you run that code and see:
[color=white][color=Blue]descendentsOf()
That means that you initialized the code for the function. It doesn’t mean that the function itself gets executed, however. That’s something you’ll have to do separately. Just as you do “getCurrentSelection()” to invoke the ‘getCurrentSelection’ function.
In the case of your example function, it also requires a single parameter; specifically, an object. You specify parameter right after the name of the function to invoke that function with that parameter. For example, to run that function on the currently selected (single) object:
descendentsOf $
You can then easily make it more robust so that it won’t die when you have no objects selected, or more than one object, etc. but that’s another question/topic
[/color][/color]
Thanks very much ZeBoxx2, that is a great explanation…and to recap …to make sure I understand what you are saying I would:
[i]fn descendentsOf obj =
(
– if want parent object in the array returned use:
–local descendents = #(obj)
– if just want descendents in the array returned use:
local descendents = for child in obj.children collect child
local i=0
while (i+=1) <= descendents.count do
join descendents (for child in descendents.children collect child)
descendents
)
—-new
descendentsOf myObj
That about right? Thanks again…I really appreciate the pointers
yep – which should then return a hierarchical array of all the children, grandchildren, etc. of the object stored in the myObj variable