generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: OOP help

Previous Thread :: Next Thread 
PrimeStarxxx is not online. PrimeStarxxx
Joined: 09 May 2017
Total Posts: 88
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
PrimeStarxxx is not online. PrimeStarxxx
Joined: 09 May 2017
Total Posts: 88
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 is not online. 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
guagiguagua is not online. guagiguagua
Joined: 15 Dec 2016
Total Posts: 206
19 Oct 2017 06:57 PM
i thought using a semicolon calls a function
and using a period calls its inherited objects
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
Horrible_Pun is not online. Horrible_Pun
Joined: 13 May 2017
Total Posts: 5102
19 Oct 2017 06:59 PM
:i thought using a semicolon calls a function"
semicolons are useless IIRC in lua.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
19 Oct 2017 07:00 PM
"semicolons are useless IIRC in lua."
He meant a not-semi semicolon, which is filtered.


Report Abuse
chimmihc is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
Horrible_Pun is not online. Horrible_Pun
Joined: 13 May 2017
Total Posts: 5102
19 Oct 2017 07:04 PM
You can use it for that, but not necesarily.
Report Abuse
PrimeStarxxx is not online. PrimeStarxxx
Joined: 09 May 2017
Total Posts: 88
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image