Jump to content

Wouldn't this be an argument mismatch?


Recommended Posts

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 were

RunAway = 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

I am only a hobbyist modder, but I think the first variable "self" is being auto-filled somehow (words of an expert :p).

 

Regarding the second point: The additional variables are optional. The function takes as many as it gets and runs. Tests such as

if fn then    fn(inst, stuff)end

make sure you don't have to declare that variable, but can do.

Link to comment
Share on other sites

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.

×
  • Create New...