Tuesday, 02 December 2008
 
  Home arrow Forum  
Main Menu
Home
News
Forum
Documentation
Download
Links
Administrator
Login Form
Welcome, Guest. Please login or register.
December 02, 2008, 09:15:20 AM
Username: Password:
Login with username, password and session length

Forgot your password?
File input problems
DSLua Community
Welcome, Guest. Please login or register.
December 02, 2008, 09:15:20 AM
1723 Posts in 315 Topics by 6337 Members
Latest Member: TrourfKeereig
DSLua Community  |  General DS Programming Chats  |  Code Hashing  |  File input problems « previous next »
Pages: [1]
Author Topic: File input problems  (Read 708 times)
Samji
New Moon
*
Posts: 6


« 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 Smiley
« Last Edit: November 30, 2007, 04:59:31 PM by Samji » Logged
Jeremysr
Waxing Gibbous
****
Posts: 254



WWW
« Reply #1 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.  Undecided

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 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.
Logged
Samji
New Moon
*
Posts: 6


« Reply #2 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.
Logged
Pages: [1]
« previous next »
    Jump to:  



    (C) 2008 DSLua

    DSLua - Best scripting language for Nintendo DS home-brew!