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 access in Lua Player

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



Joined: 16 Aug 2005
Posts: 2

PostPosted: Tue Aug 16, 2005 8:53 am    Post subject: File access in Lua Player Reply with quote

I'm trying to port a simplified version of the tile engine in the PC role playing game I'm working on to the PSP. At first I tried to use pspsdk but I couldn't find an easy way to draw 2D graphics and images to the screen (only 3D graphics which I'm not very good with). So instead I decided to use Lua Player which turned out to be really good.

However I'm having some trouble reading from a file. My code successfully reads the first variable from the file but doesn't seem to get any more after that.

Here's an extract from my code from where I access the file:
Code:

...
   success = io.input(file)
   if success == nil then
      screen:print(10,10,"Error - Failed to open level file",white)
   else
      pic = 0
      px = 0
      py = 0
      shift = 0
      
      -- Get the number of tiles in the level
      BLU_num_of_tiles = io.read("*number")
      screen:print(10,10,BLU_num_of_tiles,white)

      -- Scan through the tiles
      q = 0
      while q < BLU_num_of_tiles+1 do
            q = q + 1
         
         -- Get tile information from file
         BLU_tile_names[q] = io.read("*line")
         screen:print(10,10,BLU_tile_names[q],white)

         trans = io.read("*number")
         tick_rate = io.read("*number")

         -- Load the tiles
         BLU_load_tile(BLU_tile_names[q], q, trans)
      end
...


And here's an extract from the start of the file I'm trying to access:
Code:

162
tiles/grass3.dat
0
48
tiles/blbigcliff.dat
0
1
tiles/brbigcliff.dat
0
0

(first line is the number of tiles to be loaded, then after that there are 162 groups of three variables)

Obtaining the first number from the file (after the "-- Get the number of tiles in the level" comment) works perfectly. But attempts to access the next variables within the while loop fail returning nil.

I put in the screen:print's to make absolutely sure the BLU_tile_names[q] was empty. It seems to be, I get the following error:
Code:
error: index.lua:58: bad argument #2 to `print' (string expected, got nil)


Any idea what I may be doing wrong?
Back to top
View user's profile Send private message
essoft



Joined: 16 Aug 2005
Posts: 2

PostPosted: Tue Aug 16, 2005 6:57 pm    Post subject: Reply with quote

I've solved the problem. It was actually due to the BLU_load_tile(BLU_tile_names[q], q, trans) function I was calling in the loop resetting q to 0 (I didn't know variables of the same name can't be used in different functions in lua). The file access was working all along.
Back to top
View user's profile Send private message
StouffR



Joined: 15 Sep 2005
Posts: 11

PostPosted: Tue Sep 20, 2005 10:49 pm    Post subject: Load a picture Reply with quote

Hi !

I try like you to dev a 2D Game.
I saw, you have find a solution to load it ?

How are you to do ?

Do you know SDL ?
Back to top
View user's profile Send private message MSN Messenger
Gary13579



Joined: 15 Aug 2005
Posts: 93

PostPosted: Sat Sep 24, 2005 12:16 am    Post subject: Reply with quote

What I am doing in my game is just using calling dofile..

Code:

function loadMap(mapID)
    dofile(mapID..".map")
    --Map[1][1] contains a 1, [1][2] contains a 3...


end

Code:

.map file

Map = {
{ 1, 3}
}


It works extremly well for me, and I don't have to mess around with any file functions :)
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Sat Sep 24, 2005 1:31 am    Post subject: Reply with quote

@gary
but if someone edits your file and does (not) know what he does, you are bullshitted...
(well thats always possible...)
but if you create your own level definition (which may be easy as hell)
you can check if its correct, otherwise put out an error
if you execute lua code... everything may happen... you do not know before ;)
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Sep 24, 2005 1:52 am    Post subject: Reply with quote

essoft wrote:
I didn't know variables of the same name can't be used in different functions in lua


If you use "local" (see Lua manual), it should work.
Back to top
View user's profile Send private message
Gary13579



Joined: 15 Aug 2005
Posts: 93

PostPosted: Sat Sep 24, 2005 8:21 am    Post subject: Reply with quote

LuMo wrote:
@gary
but if someone edits your file and does (not) know what he does, you are bullshitted...
(well thats always possible...)
but if you create your own level definition (which may be easy as hell)
you can check if its correct, otherwise put out an error
if you execute lua code... everything may happen... you do not know before ;)

All they have to do is look at your programs source and figure out how levels are loaded :P
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