Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to use Self, but I not understand?

Asked by 4 years ago
Edited by royaltoe 4 years ago

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)

0
Because you need to remove the "." between 100.00 and an "," plus self:account=true Sametics -4 — 4y
0
Lol Sametics stop make me false hope! NiniBlackJackQc 1562 — 4y
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. doncellanerdy 21 — 4y

Answer this question