Weird Parameter Passing Problems

Hey guys,

I’ve been messing around with saving and loading and I wrote another file: file.lua that contains all the functions that I would need to do my operations.

However the problem I’m having is that when I’m saving, I would pass in 2 parameters and then one of them would always be nil and then 2nd one would be one of the 2 parameter I passed in,

The weird thing is that when I paste the code directly into my main.lua everything works.

I’ve tried adding a 3rd parameter and seeing what happens and it looks like the function for some reason skips the 1st parameter I pass in, assigns the 2nd parameter I pass in as the 1st one, the 3rd parameter I pass in as the 2nd one, and the 3rd parameter is just nil.

Any ideas?

When you declare a function like:

function file:saveTable()

with the : operator, there is an implied “self” variable that is expected.  So if you don’t call it with a :, but a period like you are, then the first parameter gets sucked into the “self” variable, meaning you’re going to come up one parameter short.

I would change your function definition to be:

function file . saveTable(…)   instead of:

function file : saveTable(…)

Rob

It works! Thanks for the fast response!

When you declare a function like:

function file:saveTable()

with the : operator, there is an implied “self” variable that is expected.  So if you don’t call it with a :, but a period like you are, then the first parameter gets sucked into the “self” variable, meaning you’re going to come up one parameter short.

I would change your function definition to be:

function file . saveTable(…)   instead of:

function file : saveTable(…)

Rob

It works! Thanks for the fast response!