File Reading

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Koba
Posts: 59
Joined: Thu Sep 29, 2005 10:57 am

File Reading

Post by Koba »

@everyone: is there any way to get lua to read from a text file?
if not then, @Shine: have you put any thought into I/O text file reading for LUA yet?
BePe86
Posts: 10
Joined: Sun Oct 02, 2005 3:36 am
Location: Norway

Post by BePe86 »

yes, it is fully possible to both read and write from files.

Examples:

function ReadSystemSettings()

file = io.open("settings.cfg", "r")
Pointer.x_pos = file:read("*l")
Pointer.y_pos = file:read("*l")
file:close()
end

function SaveSystemSettings()
ToggleUSB(false)
file = io.open("settings.cfg", "w")
file:write(Pointer.x_pos .. "\n")
file:write(Pointer.y_pos)
file:close()
end
EU PSP 1.52 -> 2.0 -> 1.50
Untold Legends
32MB + 1GB Memory Sticks
Koba
Posts: 59
Joined: Thu Sep 29, 2005 10:57 am

Post by Koba »

so, what i want to read and write a file for is for a sorta of save state in my game, say you buy a object, then the script will write to the file "object1 = BOUGHT" and then when you turn the game off, and start it again, the object will already be purchased. stuff like that, so it is possible to read variables and stuff from a text file? or is it just basic read/write simple text so far?
BePe86
Posts: 10
Joined: Sun Oct 02, 2005 3:36 am
Location: Norway

Post by BePe86 »

You can read from files into variables if that's what you mean...

How you implement it is up to you, since there are many differnets ways to do that.
EU PSP 1.52 -> 2.0 -> 1.50
Untold Legends
32MB + 1GB Memory Sticks
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Koba wrote:so, what i want to read and write a file for is for a sorta of save state in my game, say you buy a object, then the script will write to the file "object1 = BOUGHT" and then when you turn the game off, and start it again, the object will already be purchased. stuff like that, so it is possible to read variables and stuff from a text file? or is it just basic read/write simple text so far?
You can read/write text, but arbitrary variable structures are possible, too. See http://www.lua.org/pil/index.html#12 for an advanced method or http://www.luaplayer.org/gallery/snake.lua.txt for a quick and dirty hack :-)
2Xtremes2004
Posts: 53
Joined: Wed Aug 31, 2005 1:43 am

Post by 2Xtremes2004 »

can the save/load feature read and write to anything other than .txt
I can save to .txt but when I try to save .cfg, it writes to my system.lua file
I want my money back!?
Post Reply