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: Select all
...
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
...
Code: Select all
162
tiles/grass3.dat
0
48
tiles/blbigcliff.dat
0
1
tiles/brbigcliff.dat
0
0
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: Select all
error: index.lua:58: bad argument #2 to `print' (string expected, got nil)