BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
|
| 11 Feb 2012 11:25 PM |
I like it, but would be awesome if it had a third parameter like so:
local hat = Instance.new("Hat", game.Workspace, "TestHat") --third is name of object
|
|
|
| Report Abuse |
|
|
Aaaboy97
|
  |
| Joined: 05 Apr 2009 |
| Total Posts: 6612 |
|
|
| 11 Feb 2012 11:27 PM |
do local a = Instance.new Instance.new = function(b, c, d) local e = Instance.new(b, c) e.Name = d end end |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2012 11:29 PM |
What Aaaboy said.
But it would still be a useful update. |
|
|
| Report Abuse |
|
|
BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 11 Feb 2012 11:33 PM |
My "Create" function which looks like this:
local part = Create'Part'{ Name = 'Blah', Parent = game.Workspace, Anchored = true, ... }
Is going to be in the next release, in the utility-library. You can use that for much the same syntax and more. |
|
|
| Report Abuse |
|
|
BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
|
| 11 Feb 2012 11:35 PM |
@Stravant
So it would work like this:
local stats = Create("IntValue"){Name = "leaderstats", Parent = player}
? |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 11 Feb 2012 11:37 PM |
Yes, and you can even layer objects too:
Create'IntValue'{ Name = 'leaderstats', Parent = player, Create'IntValue'{ Name = 'Stat1', }, Create'IntValue'{ Name = 'Stat2', }, Create'IntValue'{ Name = 'Stat3', }, }
To build an object hierarchy without any intermediate variables. |
|
|
| Report Abuse |
|
|
|
| 11 Feb 2012 11:41 PM |
That's some pretty cool syntax, Stravant.
Your coding style is so strange, though. |
|
|
| Report Abuse |
|
|
BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
|
| 11 Feb 2012 11:42 PM |
In other words....
game.Players.PlayerAdded:connect(function(player) local stats = Create("IntValue"){Name = "leaderstats", Parent = player, Create("IntValue"){Name = "Points"}} end)
Points leaderboard in three lines? Very nice. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
BCGames
|
  |
| Joined: 30 Dec 2010 |
| Total Posts: 8182 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 11 Feb 2012 11:47 PM |
"Create(game.Workspace.Part){}"
In my own code I have a function like this, I call it "Modify" though, since it doesn't make much sense for a "creation" function to not actually create anything. |
|
|
| Report Abuse |
|
|
LocalChum
|
  |
| Joined: 04 Mar 2011 |
| Total Posts: 6906 |
|
|
| 11 Feb 2012 11:48 PM |
@stravant
OMG. That's a function that I always add to code where I create lots of objects. I think I'll really like this utility library :D |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 12 Feb 2012 12:17 AM |
@stravant;
Cool. I made a create function that has similar syntax to yours. Its probably not as complex but I'm working on expanding it so I can use it in some of my other scripts. The syntax goes like:
local Brick = createObj.Create("Part"){ ["Parent"] = Workspace, ["Name"] = "Brick", ["Size"] = Vector3.new(10, 10, 10), ["Position"] = Vector3.new(10, 10, 10); --[[You can even set fake values into the part and create psuedo methods]] ["_changePos"] = function(self, vec) self.Position = vec end, ["_randomTab"] = {"Trololol", "Ohaider", "ok"} };
Part:changePos(Vector3.new(10, 25, 10))
It has some other features but I plan on publishing it when I finish adding everything I want to it. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 12 Feb 2012 12:20 AM |
"Yes, and you can even layer objects too:
Create'IntValue'{ Name = 'leaderstats', Parent = player, Create'IntValue'{ Name = 'Stat1', }, Create'IntValue'{ Name = 'Stat2', }, Create'IntValue'{ Name = 'Stat3', }, }
To build an object hierarchy without any intermediate variables."
I never thought about it but I think I could also do something very similar to this with my code ._. *Edits scripts* |
|
|
| Report Abuse |
|
|
belial52
|
  |
| Joined: 10 Oct 2009 |
| Total Posts: 8074 |
|
|
| 12 Feb 2012 01:03 AM |
| I personally like aaaboy's function that's like that... |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 12 Feb 2012 03:34 AM |
> My "Create" function which looks like this ... Is going to be in the next release
Could you maybe add support for event handlers in there as well? Something like this would be nice:
local part = Create 'Part' { Name = 'Blah', Parent = game.Workspace, Anchored = true, Touched = function(self, other) --This function is connected to the .Touched event --An extra argument of `self` is passed, since otherwise --we have no reference the part this is bound to self.BrickColor = other.BrickColor end } |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 12 Feb 2012 03:37 AM |
| I've added that to [my implementation](http://wiki.roblox.com/index.php/User:NXTBoy/Scripts/%22new%22_operator) |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 12 Feb 2012 01:49 PM |
"Could you maybe add support for event handlers in there as well? Something like this would be nice:"
I can't do it in a nice way without either using pcall when assigning every single property, which is provibitively expensive, or mainting an up-to-date list of every single event name. And what if there's something which is an event in one object, type, and a property in another? Then I'd really be in trouble!
The only option is to use a less elegant syntax (Which the code that's going out already includes!):
Create'IntValue'{ Name = 'TestEvents', [Create.E'Changed'] = function(val)
end, }
And you can also make in-line arbitrary construction code too:
Create'IntValue'{ Name = 'TestCtors', [Create] = function(self) someGlobalVar = self updateStuff() end, } |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 12 Feb 2012 04:27 PM |
His style isn't strange, it's just classic C.
"It looks nice, but I sense a disturbing lack of Rainbow Dash and Fluttershy." |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 12 Feb 2012 04:29 PM |
AAboy forgot a return...
do local a = Instance.new Instance.new = function(b, c, d) local e = a(b, c) e.Name = d return e; end end |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 12 Feb 2012 05:30 PM |
This is how I would add a third parameter to Instance.new();
local instance = Instance.new local Instance = { new = function(obj, par, name) obj = instance(obj, par) obj.Name = name return obj end } Instance.new("Part", workspace, "Heee");
--------- I was supposed to post this well over 2 hours ago, but I forgot. Once I came back, I clicked post, but I found out I got logged off because I received a warning. So this post is well over 2 hours and a few minutes late.
Heh. |
|
|
| Report Abuse |
|
|