Here's a short example of how to use io. This is part of my player save system.
Add the line
Include ("stories\\bindie\\save.lua") -- place in either global.lua or your own global script.
You can save on an event (changing levels), autosave on a timer (which is how this works - timer call is not included) or an explicit keyboard call. Obviously you then to read this back in and do whatever you need done....
function saveGame()
systime=os.date("SAVED: %X : %A %d %B, %Y (Local)")
file = io.open ("autosave.txt", "w+")
io.output(file)
io.write(systime,"\n")
playerPOS()
playerSTATS()
playerINV()
io.close(file)
end
-- *****************************************
function playerPOS()
io.write("\n","PLAYER POSITION (x,y,z)","\n")
io.write(g_PlayerPosX,";",g_PlayerPosY,";",g_PlayerPosZ,"\n")
io.write("\n","PLAYER ANGLE (x,y,z)","\n")
io.write(g_PlayerAngX,";",g_PlayerAngY,";",g_PlayerAngZ,"\n")
end
-- *****************************************
function playerSTATS()
io.write("\n","PLAYER STATS (health,thirst,hunger,energy,stamina,strength)","\n")
io.write(pHealth,";",maxHealth,"\n")
io.write(pThirst,";",maxThirst,"\n")
io.write(pHunger,";",maxHunger,"\n")
io.write(pEnergy,";",maxEnergy,"\n")
io.write(pStamina,";",maxStamina,"\n")
io.write(pStrength,";",maxStrength,"\n")
end
-- *****************************************
function playerINV()
io.write("\n","PLAYER INVENTORY (index, type, name, value, count, weight, img#, health, energy, thirst, hunger, stamina)","\n")
for i = 1, inventoryIDX, 1 do
io.write(i,";",inventoryType[i],";",inventoryName[i],";",inventoryValue[i],";",inventoryCount[i],";",inventoryWgt[i],";",inventoryImg[i],";",inventoryHealth[i],";",inventoryEnergy[i],";",inventoryThirst[i],";",inventoryHunger[i],";",inventoryStamina[i],"\n")
end
end
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD