Yue Posted March 21, 2019 Share Posted March 21, 2019 Hi, I have a question about the functions. function Script:UpdatePlayer() end function UpdatePlayer() end What is the difference between defining this function differently? Quote Link to comment Share on other sites More sharing options...
Rick Posted March 21, 2019 Share Posted March 21, 2019 function UpdatePlayer() end This is a global function and once defined you can call it from any script in your app. The other one's scope is on that entity only. So you'd first need a reference to that entities script (like entity1.script:UpdatePlayer()) to be able to call it. Note that inside UpdatePlayer() you can't use the normal self.entity because inside that script it doesn't know anything about that. So global functions work on global data or data you pass into it from a parameter (in this case you have no parameter). 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted March 21, 2019 Author Share Posted March 21, 2019 In that case as step a parameter? function Script:UpdatePlayer( self ) self.entity:Hide() end self.UpdatePlayer( self.entity ) <<< Ok? Quote Link to comment Share on other sites More sharing options...
Yue Posted March 21, 2019 Author Share Posted March 21, 2019 Ok, solved. self:UpdatePlayer(self.entity) end function Script:UpdatePlayer(entidad) entidad:Hide() System:Print(entidad) end Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.