GreatBlitz Posted October 25, 2014 Share Posted October 25, 2014 So I was going through Creature Tutorial 6 (Brains) and saw these lines of code in the tut06_brain.lua.RunAway(self.inst, "scarytoprey", AVOID_PLAYER_DIST, AVOID_PLAYER_STOP),StandStill(self.inst, function() return true end),My curiosity took me to the respective files - runaway.lua and standstill.lua. The very first lines of both files wereRunAway = Class(BehaviourNode, function(self, inst, hunterparams, see_dist, safe_dist, fn, runhome)StandStill = Class(BehaviourNode, function(self, inst, startfn, keepfn)Coming from a Java background, I feel that the arguments of the function RunAway in the first code section don't match the arguments of the function RunAway in the second code section. The first argument should be self, but instead is self.inst (because the function in the second code section asks for a 'self')The second argument should be self.inst, but is "scarytoprey".The third argument should be "scarytoprey", but is AVOID_PLAYER_DIST.The fourth argument should be AVOID_PLAYER_DIST but is AVOID_PLAYER_STOP.There should also be two more arguments which I didn't understand - fn and runhome. The same goes for StandStill - there are four args in the second code section, but only two are present in the tut06_brain.lua file. Is this something Don't Starve/Lua specific? Are the tutorials outdated? Can someone please explain? If you didn't understand, don't hesitate and ask me for a more clear explanation. Link to comment Share on other sites More sharing options...
Mobbstar Posted October 25, 2014 Share Posted October 25, 2014 I am only a hobbyist modder, but I think the first variable "self" is being auto-filled somehow (words of an expert ). Regarding the second point: The additional variables are optional. The function takes as many as it gets and runs. Tests such asif fn then fn(inst, stuff)endmake sure you don't have to declare that variable, but can do. Link to comment Share on other sites More sharing options...
Heavenfall Posted October 25, 2014 Share Posted October 25, 2014 Indeed the self is a hidden parameter. More here: http://www.lua.org/pil/16.html What it comes down to is that when coding a function these two are interchangeable function one:two(test) one.two = function(self, test) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.