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: Is this a good way to make my parts?

Previous Thread :: Next Thread 
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
24 Jul 2013 09:39 PM
function part(formfactor,size,tsurf,bsurf,name,cancollide,brickcolor,parent)
local part = Instance.new("Part",parent)
for n,o in pairs({FormFactor=formfactor,Size=size,TopSurface=tsurf,BottomSurface=bsurf,Name = name,CanCollide=cancollide,BrickColor = brickcolor,Parent = parent})do
part[n] = o
end
return part end
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 09:45 PM
I'd do it like this:

function Part(...)
local Part = Instance.new("Part")
for Property, NewProperty in pairs({...}) do
pcall(function() Part[Property] = NewProperty end)
end
return Part
end

Part({"Transparency" = 1, "Anchored" = false})
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:13 PM
But, Iterations... Would that even work? Because you're passing it a table for an argument, then packing that table into a table, and THEN iterating over that with pairs()... That would just return an index of [1] and a value of [table: xxxxxx]

more like:

function Part(args)
local Part = Instance.new("Part")
for Property, NewProperty in pairs(args) do
pcall(function() Part[Property] = NewProperty end)
end
return Part
end

Part{"Transparency" = 1, "Anchored" = false}

~ Rainbow Dash is best pony ~
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 10:15 PM
Yea, it should have been:

function Part(Properties)
local Part = Instance.new("Part")
for Property, NewProperty in pairs(Properties) do
pcall(function() Part[Property] = NewProperty end)
end
return Part
end

Part({"Transparency" = 1, "Anchored" = false})
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:18 PM
Or you could be even weirder with it and have it link indexes and values so you don't have to pass tables (which is stupid, but hey)

function Part(...)
local P = Instance.new("Part");
locla Props = {...};
for i = 1, #Props, 2 do
local index, value = Props[i], Props[i+1];
pcall(function() P[index] = value; end);
end
end

Part("Parent", workspace, "Transparency", 1);

It's pretty terrible to do, but hey, FUN?! nah...

~ Rainbow Dash is best pony ~
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
24 Jul 2013 10:21 PM
Mine is modified from a weld function (Still works though), so yeah. Ok guess I'll do yours then.
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:22 PM
Yes, yours will work fine. But it's pretty inefficient and not very flexible.

~ Rainbow Dash is best pony ~
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
24 Jul 2013 10:24 PM
Yay, I'm making my function that I thought was more efficient than what I usually do into something even MORE efficient. :D
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 10:28 PM
Tables are fun!
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:29 PM
Especially when working with metatables and making class constructors :D

~ Rainbow Dash is best pony ~
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 10:30 PM
Ye metatables are fun I guess.
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:33 PM
You guess? Metatables are amazing o: I got a class constructor like to work using this jacked up syntax that Lua shouldn't have to use xP

class "MathsClass" {
tag = "> ";
id = "";

MathsClass = function(t, id) -- self is added to the function environment of every function
tag = t or tag; -- self.tag because tag isn't defined anywhere else
self.id = id; -- self.id because id is defined as an argument
end;

Display = function(a)
print(tag .. a);
end;
}

class ("BaseAddClass", "MathsClass") {
baseAddValue = 10;

BaseAddClass = function(r, id)
super("Result: ", id);
baseAddValue = r or baseAddValue;
end;

BaseAdd = function(n)
super.Display((n or 0) + baseAddValue);
end;
}

mathsClass = MathsClass(nil, "Maths0");
mathsClass.Display(6);

baseAdd = BaseAddClass(3, "Maths1");
baseAdd.BaseAdd();

WITH MAH METATABLES (and some environment changing...)

~ Rainbow Dash is best pony ~
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 10:36 PM
That doesn't look very fun. ;)
Report Abuse
ember1465 is not online. ember1465
Joined: 09 Apr 2009
Total Posts: 398
24 Jul 2013 10:43 PM
It was xD I've wanted a great class constructor for ever and I'm still working on this one that ROBLOX refuses to let work because of all of the locked stuff...

~ Rainbow Dash is best pony ~
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