Hey guys. I want to learn how to use Self but I not really understand the concept. This is a script founded on the lua.org page

Account = { balance=0,
      withdraw = function(self, v)
             self.balance = self.balance - v
      end
}
function Account:deposit(v)
   self.balance = self.balance + v 
end

Account.deposit(Account, 200.00)
Account:withdraw(100.00)

My question is, why if I change the lines 10, 11 the result is not same.

Account:deposit(Account, 200.00)
Account.withdraw(100.00)

Error: Line 7 - Attempt to perform arithmetics on

I want to understand what is the (lovely) difference. I want updgrade my scripting skills x)

3 comments

0

Because you need to remove the "." between 100.00 and an "," plus self:account=true

0

Lol Sametics stop make me false hope!

0

From what I understand, self/this doesn't exist for Roblox scripting. Some methods does have a self: but it isn't universally available. So you need to pass account directly.