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: Performing arithmetic on local 't' (a nil value)

Previous Thread :: Next Thread 
hisokachan is not online. hisokachan
Joined: 23 Dec 2014
Total Posts: 121
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
hisokachan is not online. hisokachan
Joined: 23 Dec 2014
Total Posts: 121
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
iDerpyDogez is not online. iDerpyDogez
Joined: 05 Feb 2012
Total Posts: 1781
16 Apr 2017 05:25 PM
you dont need to pass the self parameter if you use the #####
Report Abuse
hisokachan is not online. hisokachan
Joined: 23 Dec 2014
Total Posts: 121
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
16 Apr 2017 05:29 PM
Are you actually reading what I'm telling you?


Report Abuse
hisokachan is not online. hisokachan
Joined: 23 Dec 2014
Total Posts: 121
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
hisokachan is not online. hisokachan
Joined: 23 Dec 2014
Total Posts: 121
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
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