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
You are not logged in. Please login or register.
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
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.
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)
==> -- NB: The text file must be located in the same directory as binaries, ie :
That would explain why it couldn't find the file
Thanks for your advice
Sponk
I'll try to add a function to get the game directory from script.
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 3 official extensions. Copyright © 2003–2009 PunBB.