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: Instance Hierarchy variables?

Previous Thread :: Next Thread 
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 10:45 AM
Hello, here's what I would like to do.

_G["GiveColour"] = function(name,colour)
local found = game.Workspace.namehere:FindFirstChild("TPart", true)
if found then
found.Name = "CPart"
found.BrickColor = colour
end
end

I want to replace "namehere" in "game.Workspace.namehere" with the argument "name" passed by calling the global "GiveColour" function.
But I don't know and can't seem to find what the format for variables in an Instance Hierarchy path has to be.

(Note: It's probably not important that it's a global function.)

Thanks.
Report Abuse
TheGamer101 is not online. TheGamer101
Joined: 14 Feb 2009
Total Posts: 11943
19 May 2013 10:49 AM
This won't work if there is more than one thing in workspace with the Name name.

_G["GiveColour"] = function(name,colour)
local namething = game.Workspace:FindFirstChild(name)
if namething then
local found = namething:FindFirstChild("TPart", true)
if found then
found.Name = "CPart"
found.BrickColor = colour
end
end
end
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
19 May 2013 10:57 AM
_G["GiveColour"] = function(name,colour)
local found = game.Workspace[name]:FindFirstChild("TPart", true)
if found then
found.Name = "CPart"
found.BrickColor = colour
end
end

Gamer's method is slower than mine.
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 11:02 AM
Aha! Thanks! It's very obvious now you told me.
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 11:06 AM
@ArceusInator Aha, so that's the format for using a variable in a Hierarchy. Good to know, since it seems more obvious than using 2 FindFirstChild methods.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
19 May 2013 11:13 AM
Yep. Using that, you can have any variable as an index. Objects, other tables, events, functions, anything.
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 11:19 AM
I see. Now I have this function.

_G["GiveColour"] = function(name,colour)
local found = game.Workspace[name]:FindFirstChild("TPart", true)
if found then
found.Name = "CPart"
found.BrickColor = BrickColor.new(colour)
end
end

Upon calling _G.GiveColour("tester","Red"), the following happens:
One "TPart" changes name and colour (Dark Stone Grey, but I'll figure that one out later I guess)

I remember seeing "for i,v in pairs(t) do..." in scripts and the wiki before. But how do I make it so that it adds every child called "TPart" to a list called t?
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 11:27 AM
I could use GetChildren() somehow, but it seems inefficient.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
19 May 2013 11:31 AM
GetChildren would be the best way.

for _,child in pairs(thing:GetChildren()) do
if child.Name == "TPart" then
table.insert(whatevertable, child)
end
end
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 11:38 AM
Ah, GetChildren returns a read-only table of an object's children, so it can be used in pairs! Interesting. I just realised I can just re-colour it and don't have to insert it into another table.

But if I did, would the table be local to the event? As in: If I call GiveColour 2 times, will the table "whatevertable" contain the results of GetChildren from the previous time(s) I called it?
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
19 May 2013 11:47 AM
It would depend on where you define the table. If it's local to the scope of GiveColour, then it would only contain things from that run. Otherwise it would contain everything.
Report Abuse
tidus019 is not online. tidus019
Joined: 12 Nov 2008
Total Posts: 132
19 May 2013 12:08 PM
Okay, thanks!
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