|
| 19 Oct 2017 06:50 PM |
can someone explain the difference between table = {} function table.x() print("hi")
end table.x()
and...
table = {} function table.x() print("hi")
end table:x()
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 06:52 PM |
| and please don't point me to the wiki i already read it its not making very much sense |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 19 Oct 2017 06:57 PM |
local t = {}
function t.a(self) print(self) end
t.a() t:a()
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 06:57 PM |
i thought using a semicolon calls a function and using a period calls its inherited objects |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 06:59 PM |
(C will refer to a not-semi semicolon, because the actual name is filtered) When you use the C, it automatically fires the function like this table.x(table) That's only useful in OOP, as you would imagine. If you define it like this:
table = {} function table:x() print(self) end
then inside of that function, you can use a special keyword variable 'self', which of course you know about. That function above is the same as this table = {} function table.x(self) print(self) end
Lua is not inherently OOP. The method syntax, (The C) adds a touch of OOP to Lua, by allowing tables to function as objects through that 'self' variable. The variable is automatically included, which can cause errors if you use the two syntax interchangeably.
Here's an example of usage. workspace.BasePlate:Destroy() -- Method syntax workspace.BasePlate.Destroy() -- Error lol workspace.BasePlate.Destroy(workspace.BasePlate) -- Regular syntax
The function 'Destroy' is the same for all Instances, so you can also do this. game.Destroy(workspace.BasePlate) -- BasePlate is the 'self' variable, so BasePlate gets destroyed.
I'm too tired to answer it further than this, but good luck on your journey!
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 06:59 PM |
:i thought using a semicolon calls a function" semicolons are useless IIRC in lua. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 07:00 PM |
"semicolons are useless IIRC in lua." He meant a not-semi semicolon, which is filtered.
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 19 Oct 2017 07:02 PM |
"semicolons are useless IIRC in lua."
They explicitly end statements, which is useful for resolving ambiguous statements. And they work as pair separators in table construction, like commas. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 07:04 PM |
"which is useful for resolving ambiguous statements." I was doing searching before you posted that, I can't find an example. AFAIK, you can use a space in between anyways, so a semicolon still isn't required.
|
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 07:04 PM |
| You can use it for that, but not necesarily. |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2017 07:14 PM |
ok thanks for ur help! :) one more question if u dont mind so in the spring artical (here ill post it)
spring = {} function spring:update() --dosent matter end
springy = {}
springy:update()
and it did wahat was in update()
to springy so can u explain? |
|
|
| Report Abuse |
|
|