Unexpected Error After Compiling to Windows

If you can’t resolve this, consider a hit - A level 1 should probably cover a review to find this bug and perhaps others.

That generally means there is an error in the scene you’re trying to go to.

You can try requiring the scene directly in main.lua i.e. require(“scene.settings”) and see if you can get the error messages being generated.

Rob

I tried requiring all of the scene files in main.lua and none of them errored. The biggest thing that’s confusing me is why this isn’t erroring in the simulator but is erroring after I compile it

Well, the general cause of “It works in the simulator but not on device” is a filename case sensitivity problem.

Consider turning on debugging for composer:

composer.isDebug = true

https://docs.coronalabs.com/api/library/composer/isDebug.html

Rob

I did some more debugging and found one of the issues. The following is the last few lines of my main file:

if loadsave.loadTable("data-settings.json") == nil then print("started settings file"); local defaultSettings = {}; defaultSettings.pSpeed = SPEED\_SLOW; defaultSettings.tutorialIsOn = true; defaultSettings.sfxIsOn = true; defaultSettings.musicIsOn = true; loadsave.saveTable(defaultSettings, "data-settings.json"); end composer.gotoScene("scene.menu");

I call the following from scene.settings:

settings = loadsave.loadTable("data-settings.json"); for k, v in pairs(settings) do print(k, v); end

And found that pSpeed is nil, no matter what value I set it to. Any ideas why this is happening? I’ve defined SPEED_SLOW earlier in the main as 2

**UPDATE** : Don’t forget to clear your documents folder before testing this.

Are you sure… SPEED_SLOW is defined?  Have you confirmed it?  That code doesn’t seem to show you’ve confirmed it.

Try this:

if loadsave.loadTable("data-settings.json") == nil then print( "SPEED\_SLOW == ", SPEED\_SLOW ) print("started settings file"); local defaultSettings = {}; defaultSettings.pSpeed = SPEED\_SLOW; defaultSettings.tutorialIsOn = true; defaultSettings.sfxIsOn = true; defaultSettings.musicIsOn = true; loadsave.saveTable(defaultSettings, "data-settings.json"); end

It’s definitely defined: https://hastebin.com/ogejotutal.lua

However, it isn’t printing “started save file” or “started settings file”

I would suggest a small change:

local defaultSettings = loadsave.loadTable("data-settings.json") if defaultSettings == nil then print( "SPEED\_SLOW == ", SPEED\_SLOW ) print("started settings file"); defaultSettings = {}; defaultSettings.pSpeed = SPEED\_SLOW; defaultSettings.tutorialIsOn = true; defaultSettings.sfxIsOn = true; defaultSettings.musicIsOn = true; loadsave.saveTable(defaultSettings, "data-settings.json"); end

You basically are throwing away your settings that you’re attempting to load since you’re testing the return value but never store the read table.

Rob

Good catch Rob.  I didn’t even see that.  :slight_smile:

  1. This should be resolved with Rob’s catch.
  1. You missed the point of my response.  You asserted something was true, but didn’t show us you were verifying it at the point where it needed to be true.  

I was trying to demonstrate basic debugging steps to you. i.e. Verify at the point you need a variable that it is set.

The basic train of thought should be:

a. I set that variable in main.lua

b. I think it should still be set here where I’m about to use it.

c. However the value is not being ‘saved’.

d. Let  me verify the variable is still set and visible here.

Thank you very much.

I think I’ve figured out a little more as to what is happening as well by doing some more debugging in this manner.

In the simulator the loadsave.loadTable(“data-settings.json”); is returning nil upon initially launching it and having cleared the sandbox but is returning an empty table upon initially launching the compiled version that I built to Windows.

Also I realized that defaultSettings.pSpeed was causing other various errors in my files.

local defaultSettings = loadsave.loadTable("data-settings.json"); print(defaultSettings); if (defaultSettings == nil) or (defaultSettings.pSpeed == nil) then print("started settings file"); defaultSettings = {}; defaultSettings.pSpeed = SPEED\_SLOW; defaultSettings.tutorialIsOn = true; defaultSettings.sfxIsOn = true; defaultSettings.musicIsOn = true; loadsave.saveTable(defaultSettings, "data-settings.json"); end print(defaultSettings.pSpeed);

This is what I ended up using to compensate for both cases.

However, now I’m wondering if I’m building correctly, because when I go to the level select page there is previous data saved however when I go into my settings scene and reset the data (through the application itself, not through Corona) it rights itself.

So, is it correct that after the game loads in the simulator I am then building it? Is there another way in which I need to open it? I feel like what’s possibly happening as well as that I’m reading older data, however I’m not sure where it would be reading this data from.

Thanks again for all of your help. I really appreciate it. Sorry if I’m making some poor mistakes but I’m really intent on working through this and learning as this is something I enjoy doing quite a lot!

The Windows desktop app’s sandbox is a different folder than the simulator’s sandbox for your app.  I’m not on my Windows machine so I’m guessing at the path, but it’s something like:

C:\Users\youruser\App Data\Roaming\App Name\documents

Note the App Data folder is likely hidden.

Rob

I believe I had an older settings file sitting around in here that didn’t have pSpeed saved. I could load the table, but it wasn’t actually complete with all of what I wanted to save from the most recent build.

This solves my problems. Thank you to all who helped and I’m glad you could help me improve my code as well even if it was a much simpler issue than it was at surface value!