Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 05:47 PM |
When creating an OOP game design, I guess you want to create a ton a _G table, with functions in it. However, should I design my functions to work on their own? And if I do have variables in one script, where the thing is being defined, will, when I call the new function, will those variables change, or variables in the script it's being called in?
Also, I currently am making my own scrollbars. Would you suggest using existing libary's, like Gloo instead? Also, my designs w/ GUIs are not clean. Should I change that too?
I want standards for creating an OOP (Library) design, like all variables should be in the function, or what not. What ARE the standards?
Should I just copy Anaminus's Gloo design system? |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 05:51 PM |
Wait, you're confusing libraries and objects...
If you want to make a library, here is how to do it:
Create a table that contains functions. Then, put that table in _G.
When you want to use the library with a script, simply define a local variable to equal the table that is in _G.
Also, functions can use any variable that existed in the environment where they were created.
If you want to make objects, then I suggest you wait until Stravant's class system is in the RbxUtility library. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 05:52 PM |
Oh, FYI, I'm doing this because my script has become to long for ROBLOX to accept. It breaks off server connections. Since my script is in a 'basic' OOP stage, I want to turn it into a design that can support creating objects such as 'Inventory' or 'Compass', like Anaminus's Gloo library.
However, I'll also need to divide my script into separate local scripts, probably about 3-5, so ROBLOX accepts the scripts, and doesn't go all 'Connection Lost', whenever a server starts.
Any Metatable hints for error detection, or using stuff like IsA() might be nice.
Also, @JulienDethurens, if you want me to go serverside for some stuff, tell me how to do so w/ OOP stuff like this, since bindable events/functions don't work server to client. (Although I plan to load stuff from _G.)
|
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 05:54 PM |
I want to make an Object Oriented solution to my game. I think I will have about 3 global variables, the table, the help table, and the project name.
I think I want to make it library style, which returns a 'class', which I can use to add stuff. Like the class might have a method named 'CreateInventoryList(Frame), which returns another class, containing the GUI, and other methods to interact with the InventoryList.
That's what OOP is about, right? |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 05:59 PM |
If you want good examples of a good way to organize your code, then the gloo library you already mentioned and the latest version of CmdUtl by Anaminus (you can find it on tumblr by searching "CmdUtl") are extremly good examples.
I really recommend you to wait until Stravant's class system is in the RbxUtility library. Then, you'll be able to use it by just loading the library with the LoadLibrary function.
Also, you should make your libraries accessible both by the server and the client, that is, unless they are specific to one or the other.
For example, libraries that work with camera manipulation would be useless on the server and libraries that work with players would be useless on the clients.
If you want to make scripts that work kind of like libraries (they provide values and functions to other scripts), but that do extra processing, then perhaps a library isn't exactly what you want, as a service could be more appropriate for that.
And also, don't forget that libraries don't need to necessarily only provide functions. They can provide values too, though that is more rare than functions. The math.huge or the math.pi values are examples of that; they aren't functions.
Also, try to use ROBLOX's objects whenever you can. For examples, don't make your own event classes to create OOP events when you could just use BindableEvents, because it'd be silly; ROBLOX's classes are handled on the C side and are probably better than yours. |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 24 Apr 2012 05:59 PM |
What do you mean your script is too long for ROBLOX to accept?
~Sorcus |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:02 PM |
I'd also suggest creating an Help function and a GetApi method, like what RbxLibraries use.
Also, LIBRARIES ARE NOT CLASSES AND ARE NOT OBJECTS EITHER.
Here is the difference:
Libraries provide functions and values for different uses. Objects provide methods that are used to manipulate the object, properties that relate to the object and that should be read only if they are not meant to be edited outside of the object, and sometimes events, which are triggered by the object when certain things related to the object happen.
Basically, libraries only provide functions that can be useful to do this or that, while objects have members that relate to themselves.
An object that provides a method that has nothing to do with the object itself makes no sense.
For example, the BreakJoints method of a part breaks the joints of the part, while the lower function of the string library is used to make any string lowercase, and has nothing to do with the string library itself. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 06:29 PM |
I know. I want to RETURN classes.
@Sorcus. It says the script is too long, and rejects the server connection. I escaped it this last update my removing about 100 lines of comments. The next update will probably result in a total lack of stuff to remove.
Also, the Methods would obviously return stuff relative to them. What is the best way to structure the code, and return stuff, as well as making a class. I mean, isn't a class just a metatable of information and functions?
The idea is the code will look like this:
local RpgEng = _G.FirelightEngine
local Inventory = RpgEng.CreateInventorySystem({TableOfItemsGoesHere}) local InventoryFrame, GUI = Inventory:AddGuiList(script.Parent.Parent.InventoryFrame,Modify(Instance.new("IntValue"), {Name = "Gold", Parent = script, Value = 50})) InventoryFrame:Update() InventoryFrame:Show() InventoryFrame.GUI.Hide.MouseButton1Down:connect(function() InventoryFrame:Hide() end)
Inventory:AddItem("Name")
local Compass = RpgEng.CreateCompass(script.Parent.Parent.Compass, "Round") Compass:SetRadius(60) Compass.Inertia = true Compass.UpdateTime = 0.7 Compass.FadeAtHeight = 90
Get it? The library returns a class, which has methods and stuff, and properties, in which I can easily structure my RPG around. I'll include different options and types, while using Gloo and custom libraries to create it.
I want to make a legitmate RPG game engine, which I'll use in my game, and include an add-in for my ship selection. (An extra mini library).
|
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 06:31 PM |
Some of that code is wrong. Whoops! Oh well.
So how should I structure my code when writing the actual library, especially with classes.
Also, Julien, I'm not waiting for updates. I might wait all year. |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 24 Apr 2012 06:32 PM |
"local Inventory = RpgEng.CreateInventorySystem({TableOfItemsGoesHere})"
That looks horrible. |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 24 Apr 2012 06:35 PM |
^ ? That looks fine to me.
Anyway, Quenty what is the size of your file? What you are saying makes no sense. Where can I see this in action?
~Sorcus |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 24 Apr 2012 06:38 PM |
"^ ? That looks fine to me. "
He used a full stop instead of colons. (A period for you Americans) |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:38 PM |
"I might wait all year."
Stravant said he'd be able to do it next month or something...
Wait.. let me find the exact message...
There:
"School stuff got in the way for now. Next month I'll start working on the stuff full-time."
It was on 4/9/2012 12:55:24 AM. |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 24 Apr 2012 06:41 PM |
@nightname, sure I wouldn't use . over : But that doesn't necessarily make it horrible to me. I don't see the problem.
Secondly, whoever said I am an American? oO
~Sorcus |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:42 PM |
"That looks horrible."
Not at all. He's doing it correctly.
He's not manipulating the RpgEng object which doesn't even exist, he's using a function provided by the RpgEng library, which does exist.
There are also some cases where methods should be used in a library, when you're really manipulating the library. An example is the GetApi method of RbxLibraries.
For example:
RbxGui = assert(LoadLibrary('RbxGui'))
You use RbxGui.CreateSlider(args) to create a slider, but you use RbxGui:GetApi() to get the API. |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:43 PM |
"sure I wouldn't use . over :"
You would, if you were working with a library. |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 06:43 PM |
I can upload my place w/ the documentation in it, and you can join, and watch the server crash.
Seriously. My script is that long.
:(
That's why I'm doing it OOP style, with like 3-4 scripts.
So how should I structure my code for classes, in the case the RbxLibrary includes them? Because I don't want to rewrite my whole code just for a few classes. Also, how should I use metatables? |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 24 Apr 2012 06:45 PM |
Then upload it. It doesn't make any sense.
~Sorcus |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:45 PM |
You probably don't need metatables for your objects. Actually, you almost certainly don't. There are extremly few cases where you'd need to do so, and in most of these cases, you're actually creating a structure, which is not what most objects are.
Just copy the way the gloo library by Anaminus does it. I'd also suggest looking at Anaminus's CmdUtl plugin, the version 5 of it. It actually uses the gloo library... :P |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2012 06:46 PM |
@Sorcus
If scripts are really really really really really really really really really long, the server will not let any player enter and will display a warning or an error message that I forgot.
It happened to me once. |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 24 Apr 2012 06:47 PM |
How long is really long?
~Sorcus |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 24 Apr 2012 06:48 PM |
"Secondly, whoever said I am an American? oO "
No, I was pointing that out to anyone else who would have read my post. Also, its pretty obvious to know you are not American - because you told me in the past you are not American, and gave me links to your blog, etc.
@Horrible OOP code
It doesn't look right to me. I use full stops to access static "classes", and colons to access objects. I know I am being pedantic - but code that looks good, feels good.
EXAMPLE from my past code:
local manager = _G.Manager; -- This is a singleton local aiManager = manager.getAIManager(); local zombieManager = aiManager:newZombieManager({}); local avianManager = aiManager:newAvianManager({}); |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 24 Apr 2012 06:50 PM |
"Also, how should I use metatables?"
Here is code from my Luascape:
-- Room class Room = {}; Room.__index = Room;
function Room:new(name) local t = setmetatable({ name = name; }, Room) return t end
function Room:nextRoom(room) return self.nextRooms[room]:start() end
function Room:printRooms() for i,v in pairs(self.nextRooms) do print(i, v); end end function Room:start() -- print(self.name.." entered") end
--[[ rom = Room:new("Day") rom:start() ]] |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 24 Apr 2012 06:52 PM |
| OK. I'm totally rewritng my game's code, but I'm going to copy and paste a lot of it. |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 24 Apr 2012 06:54 PM |
"OK. I'm totally rewritng my game's code, but I'm going to copy and paste a lot of it."
Remember!
Full stops to access classes - like Julien said, access variables like .MAX_WIDTH - and colons to access objects.
|
|
|
| Report Abuse |
|
|