forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File Reading

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Mon Oct 03, 2005 8:51 am    Post subject: File Reading Reply with quote

@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
View user's profile Send private message AIM Address
BePe86



Joined: 02 Oct 2005
Posts: 10
Location: Norway

PostPosted: Mon Oct 03, 2005 8:54 am    Post subject: Reply with quote

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
View user's profile Send private message
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Mon Oct 03, 2005 9:05 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
BePe86



Joined: 02 Oct 2005
Posts: 10
Location: Norway

PostPosted: Mon Oct 03, 2005 9:11 am    Post subject: Reply with quote

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
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Oct 03, 2005 10:56 am    Post subject: Reply with quote

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
View user's profile Send private message
2Xtremes2004



Joined: 31 Aug 2005
Posts: 53

PostPosted: Sun Oct 09, 2005 10:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group