generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How would I go about printing the properties of an object?

Previous Thread :: Next Thread 
FlamedSkull is not online. FlamedSkull
Joined: 23 May 2009
Total Posts: 1379
23 Jul 2014 02:30 PM
How can I print out the properties of an object using a simple function?
Report Abuse
HyroadCoder is not online. HyroadCoder
Joined: 15 Jul 2014
Total Posts: 813
23 Jul 2014 02:33 PM
Delay(1,function())
local block = Instance.new("Part")
print(block.BrickColor)
print(block.Transparency)
print(block.CanCollide)
--MAKE TEH PROPERTIES
end


Don't ask why I delayed it.. :3
Report Abuse
HyroadCoder is not online. HyroadCoder
Joined: 15 Jul 2014
Total Posts: 813
23 Jul 2014 02:37 PM
Oops, I did that wrong. Well, you get the picture.
Report Abuse
FlamedSkull is not online. FlamedSkull
Joined: 23 May 2009
Total Posts: 1379
23 Jul 2014 08:44 PM
Bump.

Not what I am looking for...
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 08:44 PM
Nope.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 08:50 PM
There really is no way to do this. The only alternative is to make a table containing the string form of every possible property, then use a loop to search the object for every property in the table.

This is the very reason I have stopped working on my script that saves Instances with DataStore :P
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 08:51 PM
@blockoo: I have one of those (I used IsA on a table of quite a few instances. IT WAS HORRIBLE. Just see for yourself: http://www.roblox.com/Object-Converter-Now-with-Instances-item?id=164043356)
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
23 Jul 2014 08:53 PM
Like this: (I think this is what you want)

local function PrintProperties(Brick)
Prop = {Transparency,CanCollide, Stuffs"} x = 1
repeat
print(Brick.Prop[x])
x= x+1
wait(0.01)
until x >= #Props
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:01 PM
@Notunknown
This is what I had until I quit, I tried saving typing and time by creating a table of every property and the code snippet needed to create it:

objects = {"inst0 = game.ReplicatedStorage"}
currentObjNum = 1
properties = {{"AttachmentForward", ".AttachmentForward = Vector3.new()"}, {"AttachmentPos", ".AttachmentForward = Vector3.new()"}, {"AttachmentRight", ".AttachmentRight = Vector3.new()"},
{"AttachmentUp", ".AttachmentUp = Vector3.new()"}, {"AnimationId", ".AnimationId = "}, {"Name", ".Name = ''"}, {"Offset", ".Offset = Vector3.new()"},
{"Scale", ".Scale = Vector3.new()"}, {"VertexColor", ".VertexColor = Vector3.new()"}, {"angularvelocity", ".angularvelocity = Vector3.new()"},
{"maxTorque", ".maxTorque = Vector3.new()"}, {"P", ".P = "}, {"force", ".force = Vector3.new()"}, {"D", ".D = "}, {"position", ".position = Vector3.new()"},
{"location", ".location = Vector3.new()"}, {"maxForce", ".maxForce = Vector3.new()"}, {"velocity", ".velocity = Vector3.new()"},
{"HeadColor", ".HeadColor = BrickColor.new()"}, {"LeftArmColor", ".LeftArmColor = BrickColor.new()"}, {"LeftLegColor", ".LeftLegColor = BrickColor.new()"},
{"RightArmColor", ".RightArmColor = BrickColor.new()"}, {"RightLegColor", ".RightLegColor = BrickColor.new()"}, {"TorsoColor", ".TorsoColor = BrickColor.new()"},
{"MaxActivationDistance", ".MaxActivationDistance = "}, {"BrickColor", ".BrickColor = BrickColor.new()"}, {"Material", ".Material = ''"},
{"Reflectance", ".Reflectance = "}, {"Transparency", ".Transparency = "}, {"Position", ".Position = Vector3.new()"}, {"Rotation", ".Rotation = Vector3.new()"},
{"RotVelocity", ".RotVelocity = Vector3.new()"}, {"Velocity", ".Velocity = Vector3.new()"}, {"Anchored", ".Anchored = "}, {"CanCollide", ".CanCollide = "},
{"Locked", ".Locked = "}, {"Elasticity", ".Elasticity = "}, {"Friction", ".Friction = "}, {"Size", ".Size = Vector3.new()"}, {"CFrame", ".CFrame = CFrame.new()"},

}

function stringify(obj, num, parentNum)
local instNum = "inst"..num
local objProperties = {}
local objLine = instNum.." = Instance.new('"..obj.ClassName.."') "..instNum..".Parent = inst"..parentNum.." "
local input =
for i, v in pairs(properties) do
local success = pcall(function() local test = obj[v[1]] end)
if (success == true) then
if (v[2]:find("Vector3.new()") or v{2]:find("CFrame.new()") or v[2]:find("BrickColor.new") or v[2]:find("Color3.new")) then
objLine = objLine..v[2]:sub(1, -2)..tostring(obj[v[1]])..") "
elseif (v[2]:find("''")) then
objLine = objLine..v[2]:sub(1, -2)..obj[v[1]].."' "
else
objLine = objLine..v[2]..tostring(obj[v[1]])
end
end
for i, v in pairs(objProperties) do

end
if (obj:IsA("Hat") or obj:IsA("Accoutrement")) then
table.insert(objects, instNum.." = Instance.new('"..obj.ClassName.."') "..instParent..instNum..".AttachmentForward = Vector3.new("..tostring(obj.AttachmentForward)..") "..instNum..".AttachmentPos = Vector3.new("..tostring(obj.AttachmentPos)..") "..instNum..".AttachmentRight = Vector3.new("..tostring(obj.AttachmentRight)..") "..instNum..".AttachmentUp = Vector3.new("..tostring(obj.AttachmentUp)..") "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("Animation")) then
table.insert(objects, instNum.." = Instance.new('Animation') "..instParent..instNum..".AnimationId = '"..obj.AnimationId.."' "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("BodyColors")) then
table.insert(objects, instNum.." = Instance.new('BodyColors') "..instParent..instNum..".HeadColor = BrickColor.new("..obj.HeadColor.Number..") "..instNum..".LeftArmColor = BrickColor.new("..obj.LeftArmColor.Number..") "..instNum..".LeftLegColor = BrickColor.new("..obj.LeftLegColor.Number..") "..instNum..".RightArmColor = BrickColor.new("..obj.RightArmColor.Number..") "..instNum..".RightLegColor = BrickColor.new("..obj.RightLegColor.Number..") "..instNum..".TorsoColor = BrickColor.new("..obj.TorsoColor.Number..") "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("BlockMesh") or obj:IsA("CylinderMesh")) then
table.insert(objects, instNum.." = Instance.new('"..obj.ClassName.."') "..instParent..instNum..".Offset = Vector3.new("..tostring(obj.Offset)..") "..instNum..".Scale = Vector3.new("..tostring(obj.Scale)..") "..instNum..".VertexColor = Vector3.new("..tostring(obj.VertexColor)..") "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("BodyAngularVelocity")) then
table.insert(objects, instNum.." = Instance.new('BodyAngularVelocity') "..instParent..instNum..".angularvelocity = Vector3.new("..tostring(obj.angularvelocity)..") "..instNum..".maxTorque = Vector3.new("..tostring(obj.maxTorque)..") "..instNum..".P = "..obj.P.." "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("BodyForce")) then
table.insert(objects, instNum.." = Instance.new('BodyForce') "..instParent..instNum..".force = Vector3.new("..tostring(obj.force)..") "..instNum..".Name = '"..obj.Name.."'")
elseif (obj:IsA("BodyGyro")) then
table.insert(objects, instNum.." = Instance.new('BodyGyro')
end
end
end
end

function prepareDescendants(item, itemNum)
for i, v in pairs(item:GetChildren()) do
currentObjNum = currentObjNum + 1
stringify(v, currentObjNum, itemNum)
if (#v:GetChildren() > 0) then
prepareDescendants(v, currentObjNum)
end
end
end

_G.StoreInstance = function(instance)
stringify(instance, 1, 0)
prepareDescendants(instance, 1)
end

_G.LoadInstance = function(request)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:03 PM
@Blockoo: I prefer my table of instance-types and iterating over it, using IsA on the name and if so adding the returned table of properties to the properties to be saved. Loading is then extremely simple.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:05 PM
Yeah, I ran into an issue with objects having some of the same properties as other objects. I could get around it but I'm too lazy lol. Right now I've moved on to figuring out how to "reflect" rays.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:07 PM
Like a mirror?

http://en.wikipedia.org/wiki/Specular_reflection

Try that.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:10 PM
Except we're working with 3D space, and ROBLOX's semi-strange angle system where the angle components don't match up with position components. I figured out the angles of incidence on all axes, and now I'm stuck on figuring out how to translate that angle to the opposite side of the axis of symmetry.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:12 PM
That should work for n-dimensional space.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:14 PM
I know how to get the angles I need to reflect it at, but the problem I'm having is how to translate that to a usable direction in 3D space (especially considering I'm trying to make this work for any orientation of a surface)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
23 Jul 2014 09:17 PM
d_s = 2*d_n*d_n:Dot(d_i) - d_i

Where d_i = the incident direction, d_n = the surface normal direction and d_s = the reflected angle direction. According to the article, anyway.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
23 Jul 2014 09:18 PM
Lol, I saw that and it made my brain hurt. I've been out of school for too long and it's late. I'll try working with it tomorrow.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image