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

2014/8/7

UserInfo for not-logged-in user completely blocked?

Super_Hippo Super_Hippo

2014/8/7

#
As the title says... I understand that it is not possible to store anything to the UserInfo or get any data relating to 'UserInfo.getMyInfo()', when the user is not logged in. It is also written down in the Greenfoot API in every method description which is related to the user which is playing the scenario right now. But my problem is, that even the other methods (or at least one), also do not work. I want to be able to create the scoreboard, so even if someone is not logged in, he can see the other scores. I am trying to get a list of all users with 'UserInfo.getTop()' and then save their names and two of their ints.
List top = new ArrayList(UserInfo.getTop(0));
if (!top.isEmpty())
{
    //...
}
But already the first line without everything else does not work, if you are not logged in. The scenario does not load. So is the UserInfo completely inaccessible for user who are not logged in? Found the reason. Looks like 'UserInfo.getTop(0)' returns 'null' if not logged in. But in the API this "Returns null if: •the user is not logged in" is only written in those methods in which the own UserInfo is addressed, not in 'getTop()' or other 'get'-methods. So why can't I access data when I am not logged in?
danpost danpost

2014/8/7

#
I just tested it out. It seems to me that 'getTop' and 'isStorageAvailable' are the only two methods that will work when you are NOT logged in (which is what I had suspected). The other methods are all non-static, except for 'getNearby' and 'getMyInfo', which all require the user to be logged in. Maybe you should try a positive value in line one above to actual list some of the info blocks (also, make sure that some info blocks have been saved to begin with).
Super_Hippo Super_Hippo

2014/8/8

#
danpost wrote...
I just tested it out. It seems to me that 'getTop' and 'isStorageAvailable' are the only two methods that will work when you are NOT logged in (which is what I had suspected). The other methods are all non-static, except for 'getNearby' and 'getMyInfo', which all require the user to be logged in.
Does this mean, I could only get a list of all people sorted by their "score", but I could not access their score or other ints? Because then, I can't display a scoreboard anyway.
Maybe you should try a positive value in line one above to actual list some of the info blocks (also, make sure that some info blocks have been saved to begin with).
There are already many info blocks saved. A positive number doesn't change it. 'UserInfo.getTop(1)' also returns 'null' if not logged in. Actually it should return '', but it does not. How does it work for you? By the way, is it possible to simulate being a user, which is not logged in, in Greenfoot, so before uploading?
danpost danpost

2014/8/8

#
To simulate a user that is not logged in, clear the name from the preferences/miscellaneous/playername inputbox. I guess you could have the user input their name and then, by iterating through the UserInfo blocks, find the info for that user. For me 'UserInfo.getNearby' returns an empty list and 'UserInfo.getTop' returns the normal list. I will post a demo with source so you can download and see if it works the same for you. I am using the USB version of greenfoot and it could also be that there is a difference in how it works because of that. Also, if you had, in the past, messed with the Greenfoot files themselves, that may also effect its behavior. I guess I should probably test my demo on-line before you download it. I will let you know when you can, if it does work the same here. I guess I jumped the gun. Once you get UserInfo blocks, you should be able to use the non-static methods on one of the blocks (getting scores etc). You will not be able to change anything within any of them, however.
danpost danpost

2014/8/8

#
I found out, like you initially said, that it does not work on the site the same as it does in Greenfoot. That is, while running Greenfoot locally, 'getTop' works (as well as all the methods on the UserInfo blocks); but, on the Greenfoot site, the scenario just stops running, I will presume, when 'getTop' is called. This inconsistency should be brought to the attention of the Greenfoot team as they should work similarly (as the local usage should simulate the on-site behavior). It would be nice if the local version was the correct behavior and the on-site version was adjusted accordingly.
Super_Hippo Super_Hippo

2014/8/8

#
danpost wrote...
To simulate a user that is not logged in, clear the name from the preferences/miscellaneous/playername inputbox.
Good to know, thank you. Just found a German translation of the API and there it also says for 'getTop' that is doesn't work for users who aren't logged in, but in the original it is not. Yes, it would be great if this could be adjusted!
davmac davmac

2014/9/8

#
I will chat with Neil (who did the UserInfo implementation) and see if there's a technical reason why it is the way it is, and whether it can easily be changed. However, I'm not sure if there's really any point being able to access the scores when the user isn't logged in.
Super_Hippo Super_Hippo

2014/9/8

#
Thank you! The point is for example, that it would give the possibility to see the highscore table in a game, so guests can see what rank they would be. And maybe they will see the advantage of being a user and they will create an account.
danpost danpost

2014/9/8

#
@davmac, regardless, they should be consistent. That is, the behavior while testing locally should represent the on-line behavior. As is, they are not consistent.
davmac davmac

2014/9/9

#
danpost wrote...
That is, the behavior while testing locally should represent the on-line behavior. As is, they are not consistent.
From the UserInfo documentation:
Always use UserInfo.isStorageAvailable() to check before accessing the user data.
So actually, you are breaking the API specification if you try to access the high scores when isStorageAvailable has returned false (or has not been called at all), and the behavior is undefined. This is perfectly consistent between the two environments (online and in the IDE) - it is undefined, and it may or may not "work" in either case; whether it does so is an implementation detail that should not be relied upon. However, I will note the original request (allow getTop(...) to function when not logged in) as a feature request to be implemented for a future release.
Super_Hippo Super_Hippo

2014/9/9

#
API wrote...
isStorageAvailable public static boolean isStorageAvailable() Indicate whether storage is available. Storage is unavailable if the scenario is run as an applet outside the Greenfoot website, or as a stand-alone application, or if the user is not logged in to the Greenfoot website. This last case is very common, so you should check this function before attempting to use the other static storage functions. If this function returns false, your scenario should proceed without using storage.
The only other static functions are 'getNearby', getRank', 'getMyInfo' and 'getTop'. 'getInt' for example is not listed as static. 'getTop' only returns a list of all users which played the scenario yet (in the order of their 'score'). So it also has to be possible to access the score/ints(/Strings). Maybe this is already working (not listed as static) and only 'getTop' needs to be fixed (because it is static -> not working if not logged on, see quote above), that would be great!
davmac davmac

2014/9/9

#
Super_Hippo, calling a non-static method requires first calling a static one (to get an instance of UserInfo on which to call the non-static method...).
'getTop' only returns a list of all users which played the scenario yet (in the order of their 'score')
Yes, but you must (currently) not call 'getTop' if 'isStorageAvailable' has returned false.
So it also has to be possible to access the score/ints(/Strings). Maybe this is already working (not listed as static) and only 'getTop' needs to be fixed
The score/ints/Strings are accessed via instance methods, which you cannot call unless you have an instance to call them on. The only way you can get such an instance is by calling one of the static methods.
Maybe this is already working (not listed as static) and only 'getTop' needs to be fixed
They are already working in the sense that, if it were possible to call them, they should work. However it is not possible (assuming isStorageAvailable() has returned false).
Super_Hippo Super_Hippo

2014/9/9

#
With my last sentence I meant, if you make 'getTop' working, then you have these instances to call the other methods on, so it gives the solution, if the others are working, as they are described in the API. But true, I didn't express this really accurately due to my bad English... Well, I hope you will succeed in implementing it! :)
You need to login to post a reply.