Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Getting names of all properties of a instance?

I am not requesting a script, I just want to know how I would go about doing this.

Is it possible to get the names of every property in a instance as a table?

For example if a were to:

for name in pairs(Properties) do
	print(name)
end

where Properties would be a table of property names.

If anyone knows a way to get this information it would be a great help.

2 comments

0

Do you mean like for a GUI, could it retrieve its properties, and w/ a BasePart (Part/ Brick), it retrieves its properties, w/o typing code for that beforehand? Or not? Could you please expand on what you mean? :)

0

Any Instance

2 answers

✓ Accepted answer

If you either copy/paste into a script or perhaps use HTTPService to get the content of API:Class reference/Dump, you can parse the results and make the table of properties automatically.

If you use the copy/paste method, you'll want to put it into a script in this fashion:

input = [=[PASTE IT HERE]=]

The [=[ starts a string block that will not end until it gets to a ]=]. The reason to use that instead of "" is to allow for newlines.

I wrote the following parsing algorithm a while ago:

PropExists = {}
function copy(dict)
	local new = {}
	for k,v in pairs(dict) do
		new[k] = v
	end
	return new
end
local waitForNextClass = false
deprecated = {} --deprecated classes
for line in input:gmatch("[^\n]+") do
	if string.find(line, "%[deprecated%]") == nil then
		if line:sub(1, 1) ~= string.char(9) then
			waitForNextClass = false
			if string.find(line, ":") ~= nil then
				_, _, className, superClass = string.find(line, "Class ([%w_]+)%s:%s([%w_]+)")
				if deprecated[superClass] then
					deprecated[className] = true
					waitForNextClass = true
				else
					curClass = copy(PropExists[superClass])
				end
			else
				_, _, className = string.find(line, "Class ([%w_]+)")
				curClass = {}
			end
			PropExists[className] = curClass
		elseif not waitForNextClass then
			_, _, name = string.find(line, "%s+[%w_]+%s+[%w_]+%s*[%w_]*.([%w_]+)")
			if name == nil then print(line) end
			curClass[name] = true
		end
	elseif line:sub(1, 1) ~= string.char(9) then
		waitForNextClass = true
		_, _, className = string.find(line, "Class ([%w_]+)")
		deprecated[className] = true
	end
end

return PropExists

Note that it expects its input variable to start with "Class Instance [notbrowsable]" (input must exist before line 1 above). It ignores deprecated entries. It is meant to be in a ModuleScript; it returns a dictionary which you might access like this:

PropExists[className][PropertyFieldEventOrFunctionName] == true or false

ex PropExists["Part"]["Position"] will be true.

2 comments

1

I use this method but I just copy/paste the whole dump from here: http://wiki.roblox.com/index.php/API:Class_reference/Dump/raw?action=raw

0

@TheDarkOrganism Thanks for the link; I updated the answer

Unfortunatly, you can't get all properties without having a table that contains every property of that instance. (Wich you'd have to make yourself)

If you'd want to print all properties of a instance, you'd first have to store all the properties that instance has, inside a table, then iterate through that table (using a for loop) and change the properties like that.

This discussion is preserved as it was. New answers, comments, and votes are closed.