trying to transfer functions to an external class

Hey everyone,

I’ve got the functionality I’ve been working on logically correct, but now i want to move the functions to their own class, so I can easily use them elsewhere (duh). The error I’m getting is 

\code base\settings.lua:61: 'end' expected (to close 'function' at line 42) near 'else'

and involves this function: (line 42 is the start of the function, not sure why that’s not included when I put it in the code block format)

function settings:checkFiles() if(File:doesFileExist("appData.json",system.DocumentsDirectory)) then --stuff to do if the result is true. Read the json file, get time of last play, number of lives, and max lives -- local path = system.pathForFile( "appData.json",system.DocumentsDirectory ) -- local file = io.open( path,"r" ) -- if(file) then -- contents = file:read("\*a") -- gameSettings = json.decode( contents ) --io.close( file ) accessData() else -- leaving this else here if we decide to add any debugging messages. print( "Something Failed" ) end else --things to do if the file isn't there. instaniate the defualt values for lives, and max lives, set the time --Since there is no file in the local user directory, this must be the first time playing the game. Load the file from the resource directory local path = system.pathForFile( "Data/user.json", system.ResourceDirectory ) local file = io.open( path,"r" ) local contents = file:read( "\*a" ) appData = json.decode( contents ) appData.twentyFourHourTimer = os.time( ) appData = json.encode( appData ) --File:save(appdata, "appData") --now save that data to the document directory so we can read/write from it as needed local path = system.pathForFile( "appData.json",system.DocumentsDirectory ) local file = io.open( path,"w" ) file:write( appData ) io.close( file ) file = nil checkFiles() end return file end

I’m not sure why it’s expecting me to end a function in the middle of an if statement :\

Thanks in advance for the help!

It’s saying that somewhere in your function there is a broken if/else/end statement. It looks to me like it’s probably this:

-- if(file) then -- contents = file:read("\*a") -- gameSettings = json.decode( contents ) --io.close( file ) accessData() else -- leaving this else here if we decide to add any debugging messages. print( "Something Failed" ) end

The “if” is commented out, but the “else” and “end” are not.

Well, I guess all I can say to that is:

Doh!

It’s saying that somewhere in your function there is a broken if/else/end statement. It looks to me like it’s probably this:

-- if(file) then -- contents = file:read("\*a") -- gameSettings = json.decode( contents ) --io.close( file ) accessData() else -- leaving this else here if we decide to add any debugging messages. print( "Something Failed" ) end

The “if” is commented out, but the “else” and “end” are not.

Well, I guess all I can say to that is:

Doh!