I want a script that has a slice as its argument that returns the child count of that slice, as well as the child count of all of that slice's children (and its children, and its children, and so forth). Just a grand total of all the slices parented to a slice.
What's the best way to pull this off? Is there some way to do recursive for loops that would be able to go through each slice's children until it hits a slice with no children? I could probably figure this out all on my own eventually, but kind of on a time crunch due to the 2 week nature of this game jam.
Get count of all slice children (and their children, etc)?
Moderators: marionline, SDHawk
Get count of all slice children (and their children, etc)?
Last edited by Foxley on Wed Feb 06, 2019 5:13 am, edited 1 time in total.
Yes, recursion.
Note: it doesn't count the slice you pass in to it - give it a slice with no children and it returns 0.
Edit: heh, turns out this script was already in the Script dump
Code: Select all
script, descendent count, sl, begin
variable (ret, child)
child := first child (sl)
while (child) do (
ret += 1 + descendent count (child)
child := next sibling (child)
)
return (ret)
end
Edit: heh, turns out this script was already in the Script dump
Last edited by TMC on Wed Feb 06, 2019 6:19 am, edited 4 times in total.