jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:15 PM |
Hey there, I'm writing something pretty cool now. It's a handler for every class in roblox, and what does it add?
It adds the feature to add custom properties, events and methods to the class. Note that it's script-only. It will also prevent a lot of bugs.
Using the most awesome feature in Lua - metatables.
A small feature overview;
Creation of the dynamic class;
local Part = game.Workspace.Part Part = Create(Part) -- function name will differ later, just example
From that point, you can do things as;
Part.CustomEvent:connect(function(invoker) print(invoker) end)
The "connect" tells the structure that it's about an event (calling the event creation)
Part.BrickColorStorage = Part.BrickColor Note that original references still stay, so Part.Name is still possible. Nothing will change in that. This copies the BrickColor of the part into the part's "BrickColorStorage"
Part:TweenTo(Vector3.new(3,3,3), 10) -- an example of a new method.
Stay tuned - it will be released here: (favorite it for that reason so you can find it back, or bookmark this page!)
http://www.roblox.com/AddClass-item?id=112164235 |
|
|
| Report Abuse |
|
|
129K
|
  |
| Joined: 23 Aug 2011 |
| Total Posts: 19010 |
|
|
| 07 Apr 2013 03:16 PM |
| Sounds pretty cool, and good luck with your project. |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 03:19 PM |
I don't particularly understand why this is an incredible improvement over
TweenPart(part,Vector3.new(3,3,3),10)
for example...
Will
Create(Part).Parent return a Roblox part, or a custom part? What about
Create(Part):FindFirstChild("child")
or
Create(Part).Touched?
If you aren't wrapping all of these, then this isn't particularly useful at all. And if you are, that's more than sort of messy, although livable.. |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Apr 2013 03:22 PM |
That was probably overly disparaging. Essentially, my concern is that the wrapper will be so ubiquitous though only so slightly used that the actual need to attach new properties and methods directly to objects will not be used nearly as often as the wrapped objects will be, which sort of defeats the productiveness of them. |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 07 Apr 2013 03:22 PM |
Good job =D Reminds me of java for some reason. |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:24 PM |
Just to get that straight, it first checks for current roblox references. You can't overwrite them with custom values.
Part.Parent = 0 is not possible. (It will print an error in that case, it WONT error your script. That's a huge difference)
The methods part is just a nice addition, it's not that helpful. But, you can also say methods aren't really helpful because they save some character while typing, and they look more organized (altough they are a good addition to OOP, don't get me wrong).
If you just index "Part" in the above case it will return the NORMAL part. Part.Parent is also the NORMAL part. Part.Touched is the NORMAL touched event.
The thing it adds is to ADD references. I think that's a cool improvement, and very helpful.
So, this;
If you aren't wrapping all of these, then this isn't particularly useful at all. And if you are, that's more than sort of messy, although livable..
Is: Yes, I am wrapping all of them. The priority is to return roblox references. As I said you cannot overwrite them, but in the case you do it will not error, but print an error message. |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 07 Apr 2013 03:25 PM |
1 question: Do you define it just by doing: Part.Water = 10 or would you have to do something else as well? |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:27 PM |
The only thing you have to do is to overwrite the old reference with the new structure created by the function I'm writing. In the example that was 'Create'
So, in your example it would be;
Part = some roblox instance Part = Create(Part) -- Create() is the wrapper function.
Of course the above line can be trashed too if you just put it in the function directly. |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 07 Apr 2013 03:28 PM |
| When will it be released =D Time to learn something I never thought of. |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 03:29 PM |
Based on this, why is this not as convenient:
function Wrap(o) return {obj=o} end
?
It accomplishes the same things and can be easily analyzed, doesn't require metatables, etc. |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:29 PM |
| I don't know, but expect an alpha version very soon. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 07 Apr 2013 03:29 PM |
jobro, I have an idea.
if part is a string, then create the instance and then apply your script to it..
So instead of:
part = Instance.new("Part", workspace) part = Create(part)
you could use
part = Create("Part") |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:32 PM |
| @Blue: That's possible, but it will remove some of the features I want to add. |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
|
| 07 Apr 2013 03:33 PM |
| Kinda off topic here but: how's that survival game going (CntKillMe) =D |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 03:33 PM |
For instance, what?
This even allows 'Class' type forms of objects, giving certain new functionalities for a given type of part, depending on what you're using it for, by defaulting a variety of things. You'd need to make a wrapper-wrapper function using the Create method, unless you were planning on CreateFromClass or something similar, but, again, isn't this simpler, more understandable, probably faster, albeit less elegant? |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:39 PM |
Part = {Part} Part.x = 3 Error
Part.Touched - error Part[1].Touched - works
!?
I may get you wrong tough on what you are doing. But, if you have a table-like structure that has the "root" object(Part) in it, how would you retrieve the part normally?
(Like, Part.BrickColor)
That would require metatables.
Again I may get you wrong.
Also, I think you get me wrong.
I mean that there is totally NOTHING that changes on the normal syntaxis, except the fact you have to wrap the object using a function. Requires one line.
For the rest you can do everything normally. Connecting events, getting properties (custom or not-custom),set properties, call methods everything!
@Cnt: It's doing fine, you should check it out, because I just released I gigantic update! |
|
|
| Report Abuse |
|
|
crusada91
|
  |
| Joined: 04 Sep 2010 |
| Total Posts: 684 |
|
| |
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 07 Apr 2013 03:42 PM |
| How do you fire the Events that you add, though? |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 03:42 PM |
| In real applications, does it particularly matter what form you have for changing methods? Especially since the different form would differentiate between raw items and additions? |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 03:43 PM |
Just like normal events.
Roblox parts always check if they touch.
The underlying code could be ;
if touched then if ROOT.Touched then -- this checks if there is a function connected ROOT.Touched() end end
You could do the same thing with the events. It's basically a function inside a table, which is called. |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 07 Apr 2013 03:43 PM |
Half of my post apparently disappeared.
Here's what I meant:
How do you fire the Events that you add, though? Do you add a callback code when setting the event? |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 07 Apr 2013 04:14 PM |
^Read my last post too.
You can just use :connect() |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 07 Apr 2013 04:26 PM |
This has already been done (by me). i havent been talking about it but ive been working on it since i first metioned it here(last year?) and i just uploaded the newest version. check it out:
http://www.roblox.com/createObj-v-3-2-4-item?id=96126365 |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 04:28 PM |
This sounds rather useful.
Can it emulate real methods and events? |
|
|
| Report Abuse |
|
|