IO and scrollView aren't working on my device

Hi guys, this is my first topic here :slight_smile:

I’m developing a simple game, and in my simulator it works greats, but on my device the IO, which i used it to store data on text files, and scrollView are not working.

This is the IO code:

local path = system.pathForFile("data.txt",system.DocumentsDirectory) local goals = 0 local gps = 0 local goalsPerTap = 1 local tacticLvl = 1 local firstShoeLvl = 0 local function UpdateData() local f = io.open(path,"w") f:write(""..gps.."\n"..math.round(goals).."\n"..goalsPerTap.."\n"..tacticLvl.."\n"..firstShoeLvl.."") io.close(f) end local file = io.open(path,"r") if file then gps = file:read() goals = file:read() goalsPerTap = file:read() tacticLvl = file:read() firstShoeLvl = file:read() io.close(file) else UpdateData() end

And this is the scrollView code:

local widget = require( "widget" ) local shopView = widget.newScrollView{ top = goalsT.y + screenH/10, left = 0, width = screenW, height = (screenH/5) \*3, scrollHeight = screenH \* 2, horizontalScrollDisabled = true }

Hi @ofir.barka,

Thank you for posting your code, but I think you’ll need to be more specific. What exactly is “not working” in either case? Other developers (and staff) will need to explanation of what you expect to work, and what is not working.

Take care,

Brent

P.S. - Have you tried adding “print()” statements in your file IO code to see what (if anything) is being read for each line/variable?

Hi Brent,

About the scrollView - a blank white rect is shown instead of the scrollView and all the display objects in it.

And for the IO - on the computer it works great - all the data is saved and when I exit the app, and it saves the score when i open it again, therefore, I have not used print because it worked just fine.

On my phone it doesn’t saves the data so my score and all the game data are starting from 0 again.

Thanks, Ofir

Hi @ofir.barka,

For the file IO, did you read through the entire guide on reading/writing files?

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

As for the scrollView, that widget is always created “empty”. You need to insert other display objects into the view before it will work as you expect. See the examples in the documentation here:

https://docs.coronalabs.com/api/library/widget/newScrollView.html

Brent

I have read the guide and inserted display objects to the scrollView.

On my computer it works great, so i’m sure the code is fine

Hi @ofir.barka,

If images appear on the computer, but not on a device, this is 99.99% likely that you have a case-sensitive mismatch. File names are case-sensitive on devices, but not on the computer.

Brent

Yes, that was the problem - thank you very much! 

But, now i need to solve the IO problem…

I did some tests, and it turns out that when I save the data when buying something on the game shop, it does saves it.

so the problem is saving the data when leaving the app.

 I have this code to handle this - but i guess its not good…

local function onSystemEvent(event) if event.type == "applicationExit" then UpdateData() end end Runtime:addEventListener( "system", onSystemEvent )

Hi Ofir,

You probably shouldn’t save the data on the “applicationExit” event. Why can’t you just save it when the data should be updated? For example, if “goals” changes and you want to save it, why not just save it at that time? Why wait until the application exits?

Brent

Yes, I have done this, and now my app works great.

Thank you very much!

Hi @ofir.barka,

Thank you for posting your code, but I think you’ll need to be more specific. What exactly is “not working” in either case? Other developers (and staff) will need to explanation of what you expect to work, and what is not working.

Take care,

Brent

P.S. - Have you tried adding “print()” statements in your file IO code to see what (if anything) is being read for each line/variable?

Hi Brent,

About the scrollView - a blank white rect is shown instead of the scrollView and all the display objects in it.

And for the IO - on the computer it works great - all the data is saved and when I exit the app, and it saves the score when i open it again, therefore, I have not used print because it worked just fine.

On my phone it doesn’t saves the data so my score and all the game data are starting from 0 again.

Thanks, Ofir

Hi @ofir.barka,

For the file IO, did you read through the entire guide on reading/writing files?

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

As for the scrollView, that widget is always created “empty”. You need to insert other display objects into the view before it will work as you expect. See the examples in the documentation here:

https://docs.coronalabs.com/api/library/widget/newScrollView.html

Brent

I have read the guide and inserted display objects to the scrollView.

On my computer it works great, so i’m sure the code is fine

Hi @ofir.barka,

If images appear on the computer, but not on a device, this is 99.99% likely that you have a case-sensitive mismatch. File names are case-sensitive on devices, but not on the computer.

Brent

Yes, that was the problem - thank you very much! 

But, now i need to solve the IO problem…

I did some tests, and it turns out that when I save the data when buying something on the game shop, it does saves it.

so the problem is saving the data when leaving the app.

 I have this code to handle this - but i guess its not good…

local function onSystemEvent(event) if event.type == "applicationExit" then UpdateData() end end Runtime:addEventListener( "system", onSystemEvent )

Hi Ofir,

You probably shouldn’t save the data on the “applicationExit” event. Why can’t you just save it when the data should be updated? For example, if “goals” changes and you want to save it, why not just save it at that time? Why wait until the application exits?

Brent

Yes, I have done this, and now my app works great.

Thank you very much!