|
| 16 Apr 2017 05:20 PM |
My code is:
SetTransparency = function(self,t) t = math.cos(math.pi * t)/-2 + 0.5
and I'm calling self.SetTransparency(t) with a value every time. I'm not sure why it says t is nil. |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:21 PM |
| If you're using the ##### syntax you don't need the `self` parameter because it's implicit. function object:SetTransparency(t) -- `self` is an implicit parameter that's passed t = math.cos(math.pi * t)/-2 + 0.5 end |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:22 PM |
If you're using the ":" syntax you don't need the `self` parameter because it's implicit.
function object:SetTransparency(t) -- `self` is an implicit parameter that's passed t = math.cos(math.pi * t)/-2 + 0.5 end
|
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:23 PM |
I do need the self parameter.
I fixed it anyway I just needed to pass the extra self parameter. Silly mistake so doing self.SetTransparency(self,t) |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:24 PM |
I said that it's implicitly passed by Lua.
local object = {}
function object:test() print(self) end
If you call it with a "." it'll print nil because Lua won't pass the `self` parameter but with the ":" it's automatically passed.
|
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:25 PM |
| you dont need to pass the self parameter if you use the ##### |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:28 PM |
| SetTransparency = function(self,t) t = math.cos(math.pi * ##### # ### ####################### = # ## complains that self is an unknown global if I don't pass it |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:29 PM |
Are you actually reading what I'm telling you?
|
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:30 PM |
| Yes I understand using : rather than . however if I use : it still tells me that self is unknown |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:31 PM |
Define it with a ":".
`function object:func()`, not `function object.func()`. It doesn't matter if you call it with a ":" if you don't define it with one.
|
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 05:33 PM |
I'm not defining it with a . though. So how do I change . to a :
The point is. I'm not using the structure you think I am. So it doesn't work your way. I fixed the problem so it doesn't need to be continued. THanks for the all the help and insight |
|
|
| Report Abuse |
|
|
|
| 16 Apr 2017 07:20 PM |
It literally doesn't matter if you're not defining it with a ".", you could be doing it a different way. I'm actually curious to see what your code looks like because the ":" syntax DOES pass an implicit `self` parameter.
This:
local object = {}
object.func = function() end
Is the same as:
local object = { func = function() end }
The syntax where I was indexing the `object` table with a "." to define the function was just an example.
|
|
|
| Report Abuse |
|
|