Template:Tree

From Legacy Roblox Wiki
Jump to navigationJump to search
    {{{1}}}
[purge] Template documentation
The Tree template is used to display the parent-child hierarchy of an Instance. This can be useful in tutorials for showing what a reader might see in the Explorer panel.

Usage

A tree is started with the {{Tree}} template. The first and only argument should consist of one or more {{Tree/node}} templates.

{{Tree/node}} is where the real magic happens. It has three options:

  1. The first option is the ClassName of the Instance to be displayed.
  2. The second option specifies the Name to display for the Instance. If unspecified, the ClassName will be used.
  3. The third option indicates children of the Instance. If specified, it should consist of more {{Tree/node}} templates. This option has three types of behavior:
    If specified with children, an "expanded node" will be displayed next to the Instance, indicating that it has children, and is displaying them.
    If specified, but left blank, an "unexpanded node" will be displayed instead, indicating that the Instance has children, but is not displaying them.
    If unspecified, then no node will be displayed.

Note that if the third option is specified, the second option must also be specified.

Examples

The following source would display a Player's character model:

{{tree|
	{{tree/node|Model|Player|                <!-- has children -->
		{{tree/node|Part|Head|}}         <!-- has children, but doesn't display them -->
		{{tree/node|Part|Torso|}}
		{{tree/node|Part|Left Arm}}      <!-- does not have children -->
		{{tree/node|Part|Right Arm}}
		{{tree/node|Part|Left Leg}}
		{{tree/node|Part|Right Leg}}
		{{tree/node|Humanoid|Humanoid|}}
	}}
}}

Generation script

A script can be used quickly generate wiki markup for this template from an object hierarchy.


Use Execute Script to run the following script, which generates wiki code from the current selection:

-- use Execute Script...
-- Outputs tree of selected object, or entire game if nothing is selected
-- Outputs to Script in Workspace named "Tree Output"

local namespace = ""
local tree_name = "tree"
local node_name = "tree/node"
 
local exclude_children = {
	Stats	= true;
	CoreGui	= true;
	[""]	= true;
}
 
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
 
local output = ""
local tab = 0
local function recurse(object)
	tab = tab + 1
	local has_children = #object:GetChildren() > 0
	local expand = not exclude_children[object.ClassName]
	output = output .. string.rep("\t",tab).."{{"..namespace..node_name.."|"..object.ClassName.."|"..object.Name
	if has_children then
		if expand then
			output = output .. "|\n"
			for i,v in pairs(object:GetChildren()) do
				recurse(v)
			end
			output = output .. string.rep("\t",tab)
		else
			output = output .. "|"
		end
	end
	output = output .. "}}\n"
	tab = tab - 1
end
 
output = "{{"..namespace..tree_name.."|\n"
recurse(Game:GetService("Selection"):Get()[1] or Game)
output = output .. "}}"
 
local s = Workspace:FindFirstChild("Tree Output") or Instance.new("Script",Workspace)
s.Name = "Tree Output"
s.Archivable = false
s.Source = output
Game:GetService("Selection"):Set{s}