|
| 09 Jan 2015 01:39 AM |
| i recently learned how to use remote/bindable functions & events, and module scripts too, & i want to know if there are any other things similar to them or that i should learn |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 01:41 AM |
learn everything
be amazing |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 01:42 AM |
flawless :O
i woke up like this |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 03:06 AM |
| There are CustomEvents and CustomEventReceivers, but there's not much point in learning to use them. |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 03:13 AM |
learn metatables
and read the OOP articles
they enlighten you |
|
|
| Report Abuse |
|
|
| |
|
A2D8
|
  |
| Joined: 15 Jun 2014 |
| Total Posts: 548 |
|
|
| 09 Jan 2015 03:39 AM |
Metatables are pretty simple if you don't have an idiot (like a ROBLOX wiki writer) trying to explain them to you.
They're just an extra table you can attach to another one. Lua will check it for some special keys and do stuff with their values.
First off, here's how you get yourself a table with a metatable:
local mt = {} local t = {} setmetatable(t, mt)
It's that easy! Now you can start doing stuff with it. Let's change that first line:
local mt = { __index = function(t, key) print(key) end }
This is about as simple as it gets. Notice the two underscores before the name of the key, they denote a special function that Lua checks for when it does a certain action. There are a lot of these, I'll list them at the end of this post with short explanations. Let's look at what happens if you try to use this table now:
print(t.this_doesnt_exist)
You'll get this for output:
> this_doesnt_exist > nil
http://codepad.org/qWASTWjn for proof
Without the metatable, you'd only get the nil part. With it, you get to set a function that's called any time you try to index something that doesn't exist in the table yet! This is extremely useful, but I'll save that for another time. Let's look at another option:
local mt = { __newindex = function(t, key, val) print(key, val) end }
Notice that there's an extra argument. You'll see why:
t.a_new_key = 5
And here's your new output (yes, there's output!):
> a_new_key 5
Starting to see why metatables are so useful yet? Here's that list I mentioned: http://lua-users.org/wiki/MetatableEvents |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 03:41 AM |
| read the wiki article on OOP if you want an actual use for it |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 03:42 AM |
thanks @a2d8
ill try to learn it cause it does sound useful |
|
|
| Report Abuse |
|
|
|
| 09 Jan 2015 03:45 AM |
| they're not that hard just go through anamius's metatables in a nutshell and do a bit of practice and you'll be good |
|
|
| Report Abuse |
|
|
A2D8
|
  |
| Joined: 15 Jun 2014 |
| Total Posts: 548 |
|
|
| 09 Jan 2015 03:48 AM |
If you really want to know how OOP is best done in Lua, take a look at my OOP implementation:
http://hastebin.com/dijopuduga.lua
It's adapted from my game engine I've been co-developing with LPGhatguy. It's meant for LuaJIT but this version works in ROBLOX Lua. |
|
|
| Report Abuse |
|
|