Sprit sheet warnings and Black screen on device

Hey guys,

Im having 2 problems, not sure why they happen, I appreciate any help here

EDIT: [1 is RESOLVED, only problem 2 , check the code I posted in the comment below]

1)Im getting warnings on sprite sheet (I see them in terminal), it says:

“WARNING: Sequence (brick1) has an invalid index (18) that falls outside the range of valid image sheet frame indices: 1 <= index <= 16.”

The thing is, the Sequence is working perfectly fine and the index is indeed inside the range so i’m not sure what this is about, the image sheet png resolution is 480x2000, its size is 1.4mb and it has 150 of 80x80 frames.

On the simulator it works as expected, but i’m getting these warnings on terminal.

Other then these warnings about the image sheet, there are NO error or different types of warnings

2)When im making an ad hoc and put it in the device, and launch the game, all I see is a black screen

What can cause this? like I said the game runes perfectly fine on the simulator.

Roy.

Hey

Can you supply some code.

Rich

Sure I can… but what part? the image sheet part?

Roy.

EDIT : Sorry the sprite warning was my fault, I had a typo mistake in the sprite Sheet reference.

So I fixed it and now no warnings, I made a new build, I still get this black screen on the device

Roy.

I think I’ve found the issue, its the load save method im using from this article :

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

If I remove this code, no more black screen.

Here is my code:

[lua]

local json = require(“json”)

GameSettings = {}

GameSettings.initialCreate = false

GameSettings.levelsUnlocked = 0

GameSettings.highScore = 0

GameSettings.soundOn = true

GameSettings.musicOff = true

GameSettings.bigCoinLeft = 3

GameSettings.dragonFlyLeft = 3

GameSettings.playerName = " "

function saveTable(t, filename)

    local path = system.pathForFile( filename, system.DocumentsDirectory)

    local file = io.open(path, “w”)

    if file then

        local contents = json.encode(t)

        file:write( contents )

        io.close( file )

        return true

    else

        return false

    end

end

function loadTable(filename)

    local path = system.pathForFile( filename, system.DocumentsDirectory)

    local contents = “”

    local myTable = {}

    local file = io.open( path, “r” )

    if file then

         – read all contents of file into a string

         local contents = file:read( “*a” )

         myTable = json.decode(contents);

         io.close( file )

         return myTable 

    end

    return nil

end

– to load 

GameSettings = loadTable(“GameSettings.json”)

– to save

saveTable(GameSettings, “GameSettings.json”)

[/lua]

Am I doing it wrong?

Roy.

Hi @roysadaka,

The “black screen” usually points to some general error, not necessarily related to sprites in this case. Can you please read the tutorial on basic debugging and determine if you’re getting some Lua error?

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thanks,

Brent Sorrentino

@Brent Sorrentino

I did as you suggested and In the console I see this error:

   ?:0: attempt to index global ‘GameSettings’ (a nil value)

    stack traceback:

        [C]: ?

        ?: in main chunk

So as I suspected the problem is with the save load method im using

Iv’e posted the code in my comment above your comment, am I doing this right?

Roy.

Roy, is that the exact code you are using?  If so, the settings file GameSettings.json does not exist when you call loadTable and it returns nil, blowing away the table you created at the top.  Then you immediately call saveTable() with a nil table, which is why you’re getting that error.

I would restructure your code like this:

local json = require("json") &nbsp; function saveTable(t, filename) &nbsp;&nbsp;&nbsp; local path = system.pathForFile( filename, system.DocumentsDirectory) &nbsp;&nbsp;&nbsp; local file = io.open(path, "w") &nbsp;&nbsp;&nbsp; if file then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local contents = json.encode(t) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file:write( contents ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io.close( file ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false &nbsp;&nbsp;&nbsp; end end &nbsp; function loadTable(filename) &nbsp;&nbsp;&nbsp; local path = system.pathForFile( filename, system.DocumentsDirectory) &nbsp;&nbsp;&nbsp; local contents = "" &nbsp;&nbsp;&nbsp; local myTable = {} &nbsp;&nbsp;&nbsp; local file = io.open( path, "r" ) &nbsp;&nbsp;&nbsp; if file then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- read all contents of file into a string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local contents = file:read( "\*a" ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myTable = json.decode(contents); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io.close( file ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myTable &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return nil end -- to load local GameSettings = loadTable("GameSettings.json") if GameSettings == nil then &nbsp;&nbsp; &nbsp;GameSettings = {} &nbsp;&nbsp; &nbsp;GameSettings.initialCreate = false &nbsp;&nbsp; &nbsp;GameSettings.levelsUnlocked = 0 &nbsp;&nbsp; &nbsp;GameSettings.highScore = 0 &nbsp;&nbsp; &nbsp;GameSettings.soundOn = true &nbsp;&nbsp; &nbsp;GameSettings.musicOff = true &nbsp;&nbsp; &nbsp;GameSettings.bigCoinLeft = 3 &nbsp;&nbsp; &nbsp;GameSettings.dragonFlyLeft = 3 &nbsp;&nbsp; &nbsp;GameSettings.playerName = " " &nbsp;&nbsp; &nbsp;-- to save &nbsp;&nbsp; &nbsp;saveTable(GameSettings, "GameSettings.json") end

That way you can load the settings if they exist.  Then you test to make sure you were able to read them.  If you could not read them, initialize things and save the table.  Then the next time your app runs, you will have a file to load.

After wards, just call saveTable to update the saved version.  Your table should still be in memory, so you rarely need to load the data.

Thanks Rob it works now! I learned a very important lesson from your post!

Roy.

Hey

Can you supply some code.

Rich

Sure I can… but what part? the image sheet part?

Roy.

EDIT : Sorry the sprite warning was my fault, I had a typo mistake in the sprite Sheet reference.

So I fixed it and now no warnings, I made a new build, I still get this black screen on the device

Roy.

I think I’ve found the issue, its the load save method im using from this article :

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

If I remove this code, no more black screen.

Here is my code:

[lua]

local json = require(“json”)

GameSettings = {}

GameSettings.initialCreate = false

GameSettings.levelsUnlocked = 0

GameSettings.highScore = 0

GameSettings.soundOn = true

GameSettings.musicOff = true

GameSettings.bigCoinLeft = 3

GameSettings.dragonFlyLeft = 3

GameSettings.playerName = " "

function saveTable(t, filename)

    local path = system.pathForFile( filename, system.DocumentsDirectory)

    local file = io.open(path, “w”)

    if file then

        local contents = json.encode(t)

        file:write( contents )

        io.close( file )

        return true

    else

        return false

    end

end

function loadTable(filename)

    local path = system.pathForFile( filename, system.DocumentsDirectory)

    local contents = “”

    local myTable = {}

    local file = io.open( path, “r” )

    if file then

         – read all contents of file into a string

         local contents = file:read( “*a” )

         myTable = json.decode(contents);

         io.close( file )

         return myTable 

    end

    return nil

end

– to load 

GameSettings = loadTable(“GameSettings.json”)

– to save

saveTable(GameSettings, “GameSettings.json”)

[/lua]

Am I doing it wrong?

Roy.

Hi @roysadaka,

The “black screen” usually points to some general error, not necessarily related to sprites in this case. Can you please read the tutorial on basic debugging and determine if you’re getting some Lua error?

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thanks,

Brent Sorrentino

@Brent Sorrentino

I did as you suggested and In the console I see this error:

   ?:0: attempt to index global ‘GameSettings’ (a nil value)

    stack traceback:

        [C]: ?

        ?: in main chunk

So as I suspected the problem is with the save load method im using

Iv’e posted the code in my comment above your comment, am I doing this right?

Roy.

Roy, is that the exact code you are using?  If so, the settings file GameSettings.json does not exist when you call loadTable and it returns nil, blowing away the table you created at the top.  Then you immediately call saveTable() with a nil table, which is why you’re getting that error.

I would restructure your code like this:

local json = require("json") &nbsp; function saveTable(t, filename) &nbsp;&nbsp;&nbsp; local path = system.pathForFile( filename, system.DocumentsDirectory) &nbsp;&nbsp;&nbsp; local file = io.open(path, "w") &nbsp;&nbsp;&nbsp; if file then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local contents = json.encode(t) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file:write( contents ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io.close( file ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true &nbsp;&nbsp;&nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false &nbsp;&nbsp;&nbsp; end end &nbsp; function loadTable(filename) &nbsp;&nbsp;&nbsp; local path = system.pathForFile( filename, system.DocumentsDirectory) &nbsp;&nbsp;&nbsp; local contents = "" &nbsp;&nbsp;&nbsp; local myTable = {} &nbsp;&nbsp;&nbsp; local file = io.open( path, "r" ) &nbsp;&nbsp;&nbsp; if file then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- read all contents of file into a string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local contents = file:read( "\*a" ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myTable = json.decode(contents); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; io.close( file ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myTable &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; return nil end -- to load local GameSettings = loadTable("GameSettings.json") if GameSettings == nil then &nbsp;&nbsp; &nbsp;GameSettings = {} &nbsp;&nbsp; &nbsp;GameSettings.initialCreate = false &nbsp;&nbsp; &nbsp;GameSettings.levelsUnlocked = 0 &nbsp;&nbsp; &nbsp;GameSettings.highScore = 0 &nbsp;&nbsp; &nbsp;GameSettings.soundOn = true &nbsp;&nbsp; &nbsp;GameSettings.musicOff = true &nbsp;&nbsp; &nbsp;GameSettings.bigCoinLeft = 3 &nbsp;&nbsp; &nbsp;GameSettings.dragonFlyLeft = 3 &nbsp;&nbsp; &nbsp;GameSettings.playerName = " " &nbsp;&nbsp; &nbsp;-- to save &nbsp;&nbsp; &nbsp;saveTable(GameSettings, "GameSettings.json") end

That way you can load the settings if they exist.  Then you test to make sure you were able to read them.  If you could not read them, initialize things and save the table.  Then the next time your app runs, you will have a file to load.

After wards, just call saveTable to update the saved version.  Your table should still be in memory, so you rarely need to load the data.

Thanks Rob it works now! I learned a very important lesson from your post!

Roy.