Ok, now it's working, I can save the number of supplies the player loot during his game.
Heres the code I'm using to save each supply player get, so he wont have to worry about saving:
function supplies_init(e)
end
function supplies_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 80 then
PromptLocal(e,"[E] Take supply")
if g_KeyPressE == 1 then
PlaySound(e,0)
g_supply = g_supply + 1
local file = io.open("variables.txt", "w")
file:write(g_supply.."\n")
file:close()
Destroy(e)
end
end
end
I already set an auto-loading everytime player start a level. So, if player stops in a middle of a level, save his game, when he open it again, all his counters going to be restored:
if g_supply == nil then
g_supply = 0
end
load = 0
function display_init(e)
LoadImages("foldername",0)
end
function display_main(e)
if load == 0 then
local file = io.open("variables.txt", "r")
g_supply = file:read("*n", "*l")
file:close()
load = 1
end
end
not sure if that's the easiest way, but thats how I did. Hope it helps someone