Thank you Rob. Actually I think I do treat the ID as a string. I set it the preference with inverted commas:
“1234567890”
And also retrieve it as a string:
print(system.getPreference(“app”, “facebookID”, “string”))
Any ideas?
Thank you Rob. Actually I think I do treat the ID as a string. I set it the preference with inverted commas:
“1234567890”
And also retrieve it as a string:
print(system.getPreference(“app”, “facebookID”, “string”))
Any ideas?
Is this happening in the simulator or on a device?
Corona Simulator 2017.3159 (Oct 11 2017 03:05:02)
edit: Doesnt work in current 2018.0401 either.
Sidenote: When I set “a12345678901” instead of “12345678901” it works. So it must have to do with integers (even if stored as strings)
Using the daily build from yesterday, I get this:
Apr 01 11:20:24.160 Project sandbox folder: ~/Library/Application Support/Corona Simulator/tic-tac-toe-F77EC2BA9980D7E256030C4A3807403B Apr 01 11:20:24.355 Platform: iPhone / x86\_64 / 10.13.4 / NVIDIA GeForce GT 650M OpenGL Engine / 2.1 NVIDIA-10.30.25 355.11.10.10.30.120 / 2018.3252 / en-US | US | en\_US | en Apr 01 11:20:24.706 1234567890 Apr 01 11:20:32.350 Copyright (C) 2009-2018 C o r o n a L a b s I n c . Version: 3.0.0 Build: 2018.3252 Apr 01 11:20:32.354 Loading project from: ~/Desktop/tic-tac-toe Apr 01 11:20:32.355 Project sandbox folder: ~/Library/Application Support/Corona Simulator/tic-tac-toe-F77EC2BA9980D7E256030C4A3807403B Apr 01 11:20:32.424 Platform: iPhone / x86\_64 / 10.13.4 / NVIDIA GeForce GT 650M OpenGL Engine / 2.1 NVIDIA-10.30.25 355.11.10.10.30.120 / 2018.3252 / en-US | US | en\_US | en Apr 01 11:20:32.576 12345678901
with this code:
system.setPreferences("app", {userID = "123", facebookID = "12345678901", username = "Testuser"}) print(system.getPreference("app", "facebookID", "string"))
The first log was with the facebookID being “1234567890”. I’m on a Mac are you on Windows?
Rob
Im on windows, yes. When I print facebookID right after it was set, it works perfectly. But when I comment out the
– system.setPreferences(…
after restart it doesnt print the right value out any more. It does so as long as the string has less than 10 digits though OR as long as there is a character also. Weird…
That looks like Windows is storing integer values as 32-bit signed int.
In that case, 11-digits is beyond the range. The maximum positive value you can store is: 2,147,483,647
So, if you need longer numbers, store them with a preceding letter and then remove it when you use the number.
You can verify this by saving 2,147,483,648
Later, that should restore as -1
You can play with values here (to see the binary rep): http://www.binaryconvert.com/convert_signed_int.html?decimal
Thanks roaminggamer. Well, it doesnt
system.setPreferences(“app”, {userID = “121”, facebookID = “2147483648”, username = “Jean Pierre”})
in one scene and then
print(system.getPreference(“app”, “facebookID”, “string”))
in another scene WITHOUT reloading works perfectly.
Then, after commenting out the setPreferences line and reloading the app in simulator, it prints out
-2147483648
Does this help?
/edit: Oh, or did I misunderstand you and the negative sign in front is right exactly what you expected to happen?
Actually it does seem to be using signed int.
That output value was the other possibility. I wasn’t entirely sure how Windows would treat the extra bit.
Whatever the case, you can resolve this by forcing it to treat your value as a string and then removing the pad character(s) you choose.
system.setPreferences("app", {userID = "123", facebookID = "fb12345678901", username = "Testuser"})
local fbID = print(system.getPreference("app", "facebookID", "string")) fbID = string.gsub( fbID, "fb", "" )
Ok then, thank you very much for clarification.
What I still dont understand though: Why does the correct value gets printed out until the app is reloaded for the first time? Does that mean simulator saves it somehow different and then, only when I reload the app, windows takes over and the problem occurs?
My guess is after setting, if you call get, you’re getting the value from a different location (perhaps cached).
However (guessing again) when you restore it has to read from the value ‘disk’, interpret it, and then write to memory.
Somewhere along the way it gets run though a piece of code written to use or defaulting to signed-int.
Still, if it’s a string and you never convert it to a number it should stay a string and running in to maxint shouldn’t come into play. I just did a test on Windows in a clean/new project with just these two lines of code:
system.setPreferences("app", {userID = "123", facebookID = "12345678901", username = "Testuser"}) print(system.getPreference("app", "facebookID", "string"))
And it printed 12345678901, so if I never treat the value as a number, I get the full 11 character string. I changed it to:
local facebookID = "12345678901" system.setPreferences("app", {userID = "123", facebookID = facebookID, username = "Testuser"}) print(system.getPreference("app", "facebookID", "string"))
I also got 12345678901. So Lua isn’t doing a number conversion along this process. I made a slight change:
local facebookID = 12345678901 system.setPreferences("app", {userID = "123", facebookID = facebookID, username = "Testuser"}) print(system.getPreference("app", "facebookID", "string"))
and it printed:
1.23457e+010
which means it overflowed Lua’s ability to represent a number as an integer (all numbers are double floats, but Lua uses some trick of using doubles to represent int’s as ints) so it represented it as a double float and that’s probably the appropriate value.
I would look through your code and make sure you’re not treating the value as a number somewhere. You can copy and paste the code above into a new project and see if you get the same results.
Rob
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here system.setPreferences("app", {userID = "123", facebookID = "12345678901", username = "Testuser"}) print(system.getPreference("app", "facebookID", "string"))
Blank project with just these two lines. the ID is clearly set and retreived as a string.
Output as long as the setPreferences is NOT commented out: 12345678901
Output as soon as I comment out the setPreferences line and reload app: -539222987
I can confirm this is an issue on Windows, but not on macOS. Can I get you to make a small demo project, complete with config.lua, build.settings and main.lua and put it in a .zip file and use the Report a Bug link at the top of the page.
Thanks
Rob
why is a string not a string on windows?
Here you go. I just clicked on “new project” in simulator, added the two lines in main.lua and tried again. Same result: “12345678901” becomes -539222987
Hope that helps
/edit: Oh I missed the “bug report” part. I’ll now report it
Hi,
Thank you for the report.
This issue has been fixed starting from 2018.3160 daily build.Best Regards
Bektur Mambetov
Corona Labs
Jup, it works