|
| 10 May 2015 09:42 AM |
Resource: http://wiki.roblox.com/index.php?title=OOP
Account = {balance = 100}
function Account.withdraw(self, v) self.balance = self.balance - v end
a1 = Account; Account = nil ... a1.withdraw(a1, 100.00) -- OK
Why is the '...' in there?
It says it in the article:
function Account.withdraw(self, v) self.balance = self.balance - v end Now, when we call the method we have to specify on which object it has to operate:
a1 = Account; Account = nil ... a1.withdraw(a1, 100.00) -- OK
The ... is also underlined red.
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 10 May 2015 09:44 AM |
| It just states you can put stuff there. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
|
| 10 May 2015 09:46 AM |
Ohh
I got confused because it was in the code box.
I was thinking it was relating to http://wiki.roblox.com/index.php?title=...
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 10 May 2015 09:47 AM |
| when the changes are accepted it won't say that anymore |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 09:47 AM |
So the code would be like this:
Account = {balance = 100}
function Account.withdraw(self, v) self.balance = self.balance - v end
a1 = Account; Account = nil a1.withdraw(a1, 100.00) -- OK
Make Account table, with balance of 100
make a withdraw function on it, (self) relating to the function and v a random value.
self's balance is self's balance - value
a1 is Account Set Account to nil
Withdraw from a1 with the withdraw function, withdraw 100.00?
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 09:58 AM |
Bump to my latest reply.
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 10 May 2015 10:49 AM |
brotip:
These days OOP looks like a big ol' hammer, and with a big enough hammer everything starts looking like a nail. Object Oriented Programming has it's uses, but when you need to deal with a bunch of abstract classes or multiple inheritance, plus the hackish way lua implements it, it's best to avoid it. You'll write smaller code and it'll be easier to debug if you minimize how much you use OOP. You can't entirely avoid it though, since the ROBLOX API uses it. |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 10:50 AM |
Okay.
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 10:58 AM |
local acc = { balance = 100; }
acc.withdraw = function(self,amount) self.balance = self.balance - amount; end;
acc.deposit = function(self,amount) self.balance = self.balance + amount; end;
acc:withdraw(100); acc:withdraw(50); acc:deposit(150)
When you use the ':' it has an instruction to make the first parameter (in this case, self) the table or object you are calling on.
acc:withdraw(100) is the EXACT same thing as saying acc.withdraw(acc,100)
When using the method form it automatically passes the first parameter. |
|
|
| Report Abuse |
|
|
|
| 10 May 2015 10:59 AM |
ooooo
Thank you so much.
"I like to program" - Bosswalrus |
|
|
| Report Abuse |
|
|
| |
|
A2D8
|
  |
| Joined: 15 Jun 2014 |
| Total Posts: 548 |
|
|
| 10 May 2015 12:05 PM |
notfruit:
Absolute nonsense. There's nothing hackish about how Lua handles metatables; they're extremely well defined. If you think it's hackish, you're clearly not doing it right. It's also not a big hammer. My OOP code is a measly 86 lines and implements everything you mentioned and even wraps objects in userdata. If you think that's hackish, it's your own fault for not understanding Lua sufficiently. |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 10 May 2015 07:35 PM |
^ Don't worry. This knee-jerk reaction to criticism of your preferred programming paradigm is completely normal. We're here to help you.
To rephrase my statement, implementing any from of OOP in lua is inherently more time consuming than in a language that has native support for OOP, like Python or Java. This is because Lua provides the data abstractions for you to create your OWN implementation of OOP, which in some cases may be undesirable. To someone that wants to whip up a quick prototype, or just wants to test the water, OOP adds substantial overhead. Like I said, it can be useful on occasions but it isn't the solution to every problem you'll encounter.
which one looks better?
someFramework.gameManager.partSystem.partMotion:movePart(partObjectWrapper(part), someFramework.gameManager.environment.getOrigin())
or
part.Position = Vector3:new(0, 0, 0)? |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 10 May 2015 07:38 PM |
| Listen bud part:Move(part, 0,0,0) Look's better then part.Position Thats why we need setters and getters. Why roblox cant learn from objective C Ill never understand cause since they wont we all suffer. |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 10 May 2015 07:46 PM |
^ Why do we need getters and setters when they are functionally identical? The ROBLOX API is closed source, so we don't really need to focus on encapsulations and abstractions.
It sure is a sad world you guys live in, not knowing the joys of just coding instead of dealing with boilerplate code. |
|
|
| Report Abuse |
|
|
notfruit
|
  |
| Joined: 21 Sep 2012 |
| Total Posts: 1386 |
|
|
| 13 May 2015 02:13 PM |
boy am I a hypocrite.
I just used OOP :( |
|
|
| Report Abuse |
|
|
|
| 13 May 2015 03:24 PM |
| I love how you seem you think one programming paradigm fits all. |
|
|
| Report Abuse |
|
|