Jump to content

Where is the first arg?


Recommended Posts


function Script:Howdy(one,two,three,four)

System:Print(one)

System:Print(two)

System:Print(three)

System:Print(four)

end

 

function Script:Start()

self.Howdy(1,2,3,4)

end

 

prints out :

 

2
3
4
0x00000000

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

When calling "class" functions you want to use : not . so make it self:Howdy(1, 2, 3, 4)

 

When you use : behind the scenes Lua automatically passes the calling object as the first hidden parameter giving it the name 'self' which is why we can use self.variable inside these "class" functions.

 

If you really wanted to use . (dot) (which I wouldn't recommend) then you would have to pass the object yourself like:

 

function Script:Howdy(self, one, two, three, four)

end

 

self.Howdy(self, 1, 2, 3, 4)

  • Upvote 2
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...