| View previous topic :: View next topic |
| Author |
Message |
Koba
Joined: 29 Sep 2005 Posts: 59
|
Posted: Mon Oct 03, 2005 8:51 am Post subject: File Reading |
|
|
@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? |
|
| Back to top |
|
 |
BePe86
Joined: 02 Oct 2005 Posts: 10 Location: Norway
|
Posted: Mon Oct 03, 2005 8:54 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Koba
Joined: 29 Sep 2005 Posts: 59
|
Posted: Mon Oct 03, 2005 9:05 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
BePe86
Joined: 02 Oct 2005 Posts: 10 Location: Norway
|
Posted: Mon Oct 03, 2005 9:11 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Oct 03, 2005 10:56 am Post subject: |
|
|
| 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 :-) |
|
| Back to top |
|
 |
2Xtremes2004
Joined: 31 Aug 2005 Posts: 53
|
Posted: Sun Oct 09, 2005 10:56 am Post subject: |
|
|
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!? |
|
| Back to top |
|
 |
|