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

2020/5/15

userinfo

Roshan123 Roshan123

2020/5/15

#
how will i get userinfo for my game plz write in details
Roshan123 Roshan123

2020/5/15

#
plz write from import - } i mean from top to down
danpost danpost

2020/5/15

#
Roshan123 wrote...
how will i get userinfo for my game plz write in details
It is not a matter of getting -- but of using. The UserInfo class is part of the imported greenfoot package and the Greenfoot class has a method to retrieve (or create and return) a UserInfo object belonging to the current user (must be set as Player or logged in). Then, it is just a matter of invoking UserInfo instance methods on the returned object (see UserInfo API documentation).
Roshan123 Roshan123

2020/5/15

#
but when i wrote this i got errors if (UserInfo.isStorageAvailable()) { UserInfo myInfo = UserInfo.getMyInfo(); if (newScore > myInfo.getScore()) { myInfo.setScore(newScore ); myInfo.store(); // write back to server } } it cannot find variable isStorageAvailable and many more
danpost danpost

2020/5/15

#
Show entire class (select all, copy and paste) within code tags (use "code" link below or type tags in manually: Before code: open square bracket + "code" + close square bracket After code: same as before, but with "/code"
Roshan123 Roshan123

2020/5/16

#
import greenfoot.*;  
public class UserInfo extends Actor
{
if (UserInfo.isStorageAvailable()) {
         UserInfo myInfo = UserInfo.getMyInfo();
         if (newScore > myInfo.getScore()) {
             myInfo.setScore(newScore );
             myInfo.store();  // write back to server
         }
     }
}
Roshan123 Roshan123

2020/5/16

#
sorry its wrong.i havent written that
Roshan123 Roshan123

2020/5/16

#
import greenfoot.*;  
public class UserInfo extends Actor
{
public void act(){
if (UserInfo.isStorageAvailable()) {
         UserInfo myInfo = UserInfo.getMyInfo();
         if (newScore > myInfo.getScore()) {
             myInfo.setScore(newScore );
             myInfo.store();  // write back to server
         }
     }
}
}
Roshan123 Roshan123

2020/5/16

#
hey danpost plz reply
danpost danpost

2020/5/16

#
Roshan123 wrote...
sorry its wrong.i havent written that
UserInfo is already a class. You do not want to create another one. What you want to do would depend on how you intent to use the storage space available for a user. Normally, it i used just to keep track of the highest score each user achieves. Then, sometimes, an Actor subclass is created to display the high score of the current user, possibly in a list with other top scores or nearby high scores of other users. Usually, the class is called something like ScoreBoard or HighScore or HighScores.
Roshan123 Roshan123

2020/5/16

#
if i will write in like this
import greenfoot.*;  
public class UserInfo extends Actor
{
public void act(){
if (UserInfo.isStorageAvailable()) {
         UserInfo myInfo = UserInfo.getMyInfo();
         if (newScore > myInfo.getScore()) {
             myInfo.setScore(newScore );
             myInfo.store();  // write back to server
         }
     }
}
}
will it show me the scores in get data or not
Roshan123 Roshan123

2020/5/16

#
or else
import greenfoot.*;  
public class HighScore extends Actor
{
public void act(){
if (UserInfo.isStorageAvailable()) {
         UserInfo myInfo = UserInfo.getMyInfo();
         if (newScore > myInfo.getScore()) {
             myInfo.setScore(newScore );
             myInfo.store();  // write back to server
         }
     }
}
}
Roshan123 Roshan123

2020/5/16

#
which one will show the the high score in get data
danpost danpost

2020/5/16

#
Roshan123 wrote...
which one will show the the high score in get data
Neither is yet programmed to show any score. Currently, you only have code to save one; and even that is flawed as newScore appears to be undefined at the moment. Also, I do not think an act method is the right place for saving a high score. It should have a method that is invoked only at game over which will check and save a high score only if that score is indeed a new high score. Maybe an addedToWorld method can be added to later create and set the actor's image.
You need to login to post a reply.