This site requires JavaScript, please enable it in your browser!
Greenfoot back
steved
steved wrote ...

2012/8/12

UserInfo level select

steved steved

2012/8/12

#
I need to know how to save and load strings with userinfo for the levelselect of my game. Im going to need to save a string in each of my worlds when i first enter them and then load that string in my level select world. It is only one string and I already have it figured out exept for the UserInfo part.
danpost danpost

2012/8/13

#
First, let me explain that you do not load and save any part of the UserInfo object; it is all or nothing. What you do with each part (whether the score, an int, or a String) is 'get' and 'set' them. The UserInfo object, as a whole unit, is what is loaded (with 'UserInfo myInfo = UserInfo.getMyInfo();') and saved (with 'myInfo.store();'). That being said, you can see that it is a two part process. Either you load the UserInfo object and then 'get' the String (with 'String levelString = myInfo.getString(0);')from the object; or you 'set' the String (with 'myInfo.setString(0, levelString);') to the UserInfo object and then save the object. Hope this helps. EDIT: always make sure to use 'if (UserInfo.isStorageAvailable())' before working with any UserInfo objects. If it returns 'false', do not work with any UserInfo object.
steved steved

2012/8/13

#
Thanks for the help danpost! One more question though, what if you are not logged in and the 'getMyInfo()' returns null (thats what it does right?). Should I make another if statement inside of the statement that tells it not to do the stuff if it is null, or will it just not make a difference either way? EDIT: just did the code for loading and something odd is happening. I appear to be getting and error that could only be happening because it is trying to load the string and it as getting a blank string. So just to see what would happen i changed 'if(UserInfo.isStorageAvailiable())' to 'if(!UserInfo.isStorageAvailiable())' and it worked?!? Is there a reason that it appears to be operating backwards?
danpost danpost

2012/8/13

#
The way it should work is: 'if(UserInfo.isStorageAvailable())' should return false if the user is not logged in, or for some other reason the storage is not accessable; if it returns true, then you should be able to use 'UserInfo.getMyInfo()' to retrieve the user's UserInfo object. Make sure you select 'Edit'>'Preferences', select the 'Miscellaneous' tab, and enter a user name. You could also press 'Control-Shift-P' and enter the user name there.
steved steved

2012/8/13

#
I think I now udestand what heppened. My wifi was on so it was getting player1's data and it was null (just like any other players would be at this time) so the string was null. Then when I reversed it it only did it if I wasn't connected to wifi and then it looked like it worked... could that be the case? Thanks again.
DonaldDuck DonaldDuck

2012/8/13

#
When using UserInfo offline, it simply creates pseudo-users in the storage.csv file. I'm (pretty) sure that UserInfo.isStorageAvailable() will always return true offline. Keep in mind that after making a change to any users UserInfo, you must call UserInfo.store() in order for it to write the changes to the file.
danpost danpost

2012/8/14

#
DonaldDuck wrote...
I'm (pretty) sure that UserInfo.isStorageAvailable() will always return true offline.
That actually is not the case. If you set the user name to an empty string (by Control-Shift-p/Control-a/Delete and click 'OK') it will return 'false'; just as if you were not logged in.
steved steved

2012/8/16

#
Thanks guys looks like its working now. Ill probably be done with the update in a day or two. By the way the game this is for is platforms of meh.
You need to login to post a reply.