DSLua Community

General DS Programming Chats => Code Hashing => Topic started by: Samji on November 30, 2007, 04:56:11 PM



Title: File input problems
Post by: Samji on November 30, 2007, 04:56:11 PM
Hey, guys.
I'm trying to make a simple script that reads in a file and prints the first line.
This is what I have:

Code:
-- set up screens to display text
SCREEN_TOP = 1
SCREEN_BOTTOM = 0
BGTopText = Screen.LoadTextBG() BGBotText = ScreenLoadTextBG()
Screen.Initialize(SCREEN_TOP, BGTopText)
Screen.Initialize(SCREEN_BOTTOM, BGBotText)

-- read file.txt
file = io.open("file.txt", "r")
output = file:read("*line")
BGTopText:PrintXY(10, 12, "File contains:")
BGBotText:PrintXY(10, 12, output)

-- wait for any key press
DSLua.WaitForAnyKey()

I just one to display the first line from a two line text file. What's wrong? When I run this script in DSLua 0.7, I just get a blank screen.
Thanks in advance. BTW I suspect file input is what is preventing my XML parser module from working with DS Lua, that is why I wrote the above example in the first place.

Also, it it possible to just do a require() at the top of the file for a file which includes the code to initialize the screen?

Thanks :)


Title: Re: File input problems
Post by: Jeremysr on November 30, 2007, 05:59:21 PM
Quote from: Samji
I just one to display the first line from a two line text file. What's wrong? When I run this script in DSLua 0.7, I just get a blank screen.
Thanks in advance. BTW I suspect file input is what is preventing my XML parser module from working with DS Lua, that is why I wrote the above example in the first place.

Unfortunately DSLua 0.7 has a problem with displaying errors... Instead of saying what you did wrong and the line number, it just shows a blank screen.  :-\

In line 4 you put ScreenLoadTextBG() instead of Screen.LoadTextBG(), that's why it had an error. (By the way, the two statements on line 4 should probably be split into two lines. It's like that in my tutorials because I made a few mistakes with putting "<br />" wherever there were linebreaks and I guess I never did fix them.) After fixing it though I still got a blank screen and I don't know what the problem is now. Highscore saving/loading in my Skydiver game works with DSLua 0.7 on my M3 Simply (which I think is what you have if I remember right) so it's not a problem with DSLua's file functions.

You might have to wait until the next version of DSLua (which is actually a rewrite of the whole thing using C instead of PAlib) to get rid of all the bugs in DSLua 0.7, although Sypherce doesn't seem to have been working on it for a while (it's been on Revision 63 (http://dslua.googlecode.com/svn/) for a while.)

Quote from: Samji
Also, it it possible to just do a require() at the top of the file for a file which includes the code to initialize the screen?

Yes, that should work.


Title: Re: File input problems
Post by: Samji on December 01, 2007, 09:53:46 AM
Thanks for the help. I made the necessary changes and it worked fine. I tried using a require() too, but although it worked it would only work on the first run, subsequent runs would not work. Maybe the require() support needs improvement?

Thanks again. I would like to help out with DS Lua too if you'd like.