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 https://forums.kleientertainment.com/forums/topic/42801-wouldnt-this-be-an-argument-mismatch/ 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 https://forums.kleientertainment.com/forums/topic/42801-wouldnt-this-be-an-argument-mismatch/#findComment-556982 Share on other sites More sharing options...
Heavenfall Posted October 25, 2014 Share Posted October 25, 2014 (edited) 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) Edited October 25, 2014 by Heavenfall Link to comment https://forums.kleientertainment.com/forums/topic/42801-wouldnt-this-be-an-argument-mismatch/#findComment-556990 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now