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

2012/8/8

Highscores using userinfo (Asked before)

1
2
danpost danpost

2012/8/8

#
The method is 'getString(int)'. The 'int' parameter should be a number between 0 and 4 inclusive; 0 is for the first string, 1 for the second, and so on. The same format is used for the 10 general purpose 'int's. Please refer to the UserInfo API on there usage.
Zamoht Zamoht

2012/8/8

#
Okay sorry you already told me that I just didn't get it the first time. I'm pretty sure I got what I need now, though I might come back and ask about the code you posted, the post where you posted some comments on the code a short while after.
Zamoht Zamoht

2012/8/9

#
Okay lets say i have a game with 20 levels, I want to print a scoreboard for each level (not at the same time, but with some kind of page navigation). If there had only been one level I would have used the set/getScore() methods to store the scores, but since there is 20 I store the data as characters in a string. So if I had used set/getScore() I would list the five top users, and from there figure out what to do with that list, but now that I use a string the userinfo class doesn't know anything about ranking and all that. I don't know how to list the users with the highest scores when the score comes as a character. (Do I have to list all the users, and then take the character value from a specific level for each user and then somehow compare their score/character value, to end up with the 5 highest scores for that specific level). I really hope there is an easier way, but if I'm somewhat right please tell me how, and if I'm completely wrong please tell me what to do then. (Sorry for this b**** of a post) Thanks for your time.
danpost danpost

2012/8/9

#
You are pretty much right. The only way to figure out the highest score for any level would be to compare and rank them yourself (which is just a matter of sorting the UserInfo objects dependent on the value of that one character refering to that particular level.) Remember, like in the case of Kara Sokoban, if the lower score is the better score, you need to sort in ascending order (not descending). Once they are sorted, you can display to top however many scores right from the newly ordered list. EDIT: The way I would sort it is (assuming you have an array of UserInfo objects: users ): (1) create an 'int' array equal in length to the users array. (2) iterate through the UserInfo objects setting each score for the level in the new 'int' array (3) sort using the 'int' array, but also adjusting the positions of the UserInfo objects in 'users' while you adjust the 'int' values; thus, keeping their positions similar (4) use the 'users' array to get the user names and the 'int' array to get the scores and display the top few
Zamoht Zamoht

2012/8/15

#
Will this code work?
List textFields = getWorld().getObjects(TextField.class);
                
                for (Object obj : textFields)
                {
                    TextField textField = (TextField)obj;
                    textField.saveString();
                }
                
                UserInfo myInfo = UserInfo.getMyInfo();
                myInfo.store();
public void saveString()
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        myInfo.setString(string, stringToStore);
    }
It's simply a button that should save strings from text fields.
SPower SPower

2012/8/15

#
add this line to saveString:
myInfo.store();
Zamoht Zamoht

2012/8/15

#
Makes sense. First i thought that I could just do the store in the button code as you can see on line 9 and 10, but line 9 would just get the old info, which means that it wouldn't save anything at all. Please tell me I'm right. (:
SPower SPower

2012/8/15

#
You're right: when you wouldn't do it in the saveString method, that string will be probably gone.
Zamoht Zamoht

2012/8/18

#
Is it possible to get a totally random userinfo, use that users data, but of course not change the users data. Like how would you show the profile picture of a totally random user using userinfo.
danpost danpost

2012/8/18

#
@Zamoht, Yes. But you must first create a list of ALL users who have run the scenario while logged in. Once you have created the list (UserInfo userInfos), you can 'UserInfo user = userInfos;' to get a random user; and then, 'GreenfootImage randomImage = user.getUserImage();' to get the profile picture. The most difficult thing of it is creating a complete list of All users who have run the scenario while logged in. See the discussion 'On 'Private Messaging by danpost''. Sorry, that information was not supplied there yet. Will be there shortly.
Zamoht Zamoht

2012/8/18

#
Thanks. I hope you upload the information, because I have no idea how to make the Array.
You need to login to post a reply.
1
2