Topic: Access to files outside the games .npk

Hello community,

I want to read a configuration file from outside the npk via lua into my game.

First: Is that possible?
Second: How do have to do that?

Sponk

Re: Access to files outside the games .npk

I guess you can use "file = io.open(filename, "r")" to read a file,
as for the path I'm not sure as I never tested it, it's a standard lua library that handle it and not Maratis.

Re: Access to files outside the games .npk

Here is a complete example with a few tips on file locations:

function settingsFromFile()

-- NB: The text file must be located in the same directory as binaries, ie :
--         "/Maratis/Bin" for unpublished projects
--        "/MyProject/published" for published projects

    file = io.open("Settings.txt", "r") -- open file in read ("r") mode

    if file then -- catch IO errors

        settings = {} -- create an array containing all file's lines (each one is a parameter)
        for line in file:lines() do table.insert(settings, line) end

        -- Set parameters
        force = settings[1]

        file:close() -- close file

    end

end

settingsFromFile()

-- scene update
if onKeyDown("B") then addCentralForce(Player, {0, 0, force}, "local") end

Last edited by com3D (2013-05-10 11:36:44)

Re: Access to files outside the games .npk

==> -- NB: The text file must be located in the same directory as binaries, ie :
That would explain why it couldn't find the file wink

Thanks for your advice big_smile

Sponk

Re: Access to files outside the games .npk

I'll try to add a function to get the game directory from script.