oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 06 Feb 2012 07:19 PM |
| This is known as associative arrays. Things like CodeIgniter use this a lot. |
|
|
| Report Abuse |
|
|
1Ra
|
  |
| Joined: 02 May 2010 |
| Total Posts: 2400 |
|
|
| 06 Feb 2012 07:19 PM |
*presses F5*
now the mods can see it because in refreshed on my personal computer! |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 06 Feb 2012 07:20 PM |
| You'll be happy to head that my "Create" function which may be in the next release' RbxUtility library does exactly that. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 06 Feb 2012 08:15 PM |
"Woah that will be cool, but why not just add my idea?"
Because, that would add complexity to vanilla code. The nice thing about libraries is that you don't have to use them, and stuff like my create function will be fairly limited in it's use to more experienced scripters.
Also, it's a very non-obvious technique, so it doesn't make sense to include it in the core API. Some reason stuff like boost::spirit isn't in the C++ standard library. |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 07 Feb 2012 10:31 AM |
But couldn't it be made with function like this, function Create(str,tbl) s = Instance.new(str) for i,v in pairs(tbl) do s[v[1]] = v[2] end return s end part = Create("Part",{{"Name","Bob the part"},{"Anchored",true},{"Position",Vector3.new(0,10,0)}}) part.Parent = workspace ? |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2012 10:38 AM |
@xlegox
can you make c-side stuff?
if so can you add a :GetProperties() method that returns a key/value table of properties and values in that object?
that'd be like, uber helpfull |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 07 Feb 2012 11:54 AM |
local properties = {} function create(...) --if you'd like; change properties local obj = Instance.Part("Part") if properties["Parent"] then obj.Parent = properties["Parent"] elseif not properties["Parent"] then obj.Parent = workspace end for _,v in pairs (properties) do obj[_] = v end for _,v in pairs (...) do obj[_] = v end return obj end |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2012 02:06 PM |
@Oysi
" local p = Instance.new("Part") p.Anchored = true p.Size = Vector3.new(1, 1, 1) p.CFrame = CFrame.new(0, 10, 0) p.Parent = workspace "
or we could alternatively use lQuery :D
local p = _('Part').SetAnchored(true).SetSize(Vector3.new(1,1,1)).SetCFrame(CFrame.new(0, 10, 0).SetParent(Workspace) |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
|
| 07 Feb 2012 02:24 PM |
What about..
Instance.new(string classType[, object parent[, table properties]])?
Like Instance.new("Part", workspace, {Name = "Hai", Transparency = 0.3} |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 07 Feb 2012 03:22 PM |
@cap Isn't that what he's saying? Also this isn't that difficult of a thing to do
function create(className,associative) local new_object=Instance.new(className); for i,v in pairs(associative) do pcall(function() new_object[i]=v; end); end return new_object; end create("Part",{Name="Hai";Transparency=0.3;Parent=workspace}); |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2012 03:47 PM |
| Ew, only Oysi has posted a nice implementation so far, though I'm biased in that because I've made that same implementation, and I believe stravant has as well. Not having to use parentheses in the function call because of some nice Lua syntax sugar = <3 |
|
|
| Report Abuse |
|
|
|
| 07 Feb 2012 03:48 PM |
@Oysi
Not realy, I kinda gave up on it, but it would've eventually had proper vector3 and CFrame manipulation. Vector3 manipulation does work, just not integrated with object manipulation.
it's even got variable hax so you can do this:
local x = _('Part').SetTransparency(lC.GetTransparency + 0.1) |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 07 Feb 2012 03:53 PM |
My version of this (although not exactly original):
with (Instance.new"Part") { Parent = workspace; Name = "Awesome part"; Anchored = true; Position = Vector3.new(0,100,0); } |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
22436106
|
  |
| Joined: 19 Dec 2011 |
| Total Posts: 90 |
|
|
| 08 Feb 2012 06:35 AM |
qi = function(ttz) local qii = it(ttz[1]) table.foreach(ttz,function(oi,oi2) if oi ~= 1 and oi ~= 2 then qii[oi] = oi2 end end) qii.Parent=ttz[2] return qii end
qi({"Part",workspace,Anchored=true,Name="lal",CFrame=CFrame.new(0,10,0)})
|
|
|
| Report Abuse |
|
|