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

2021/12/21

How to save 2 UserInfo at a time?

Roshan123 Roshan123

2021/12/21

#
I don't know why but seldomly in my scenario the score is not being saved in website. A method ("gameover") is called from MyWorld which saves 2 data at a time but I don't know what am I supposed to do inorder to prevent the problem. Currently I m not i desktop, so that's why I m not able to post the specified code
Super_Hippo Super_Hippo

2021/12/21

#
Offline it seems to work. Which one does it store online and which one doesnt? Anyway, this might fix it: Current code:
        if(UserInfo.isStorageAvailable()) 
        {
            UserInfo myData1 = UserInfo.getMyInfo();
            if (myData1 != null) 
            {
                int highScore = counter.getScore();
                if ( highScore>myData1.getScore())
                {
                    myData1.setScore(highScore);
                    myData1.store();
                }
            }
        }
        if(UserInfo.isStorageAvailable()) 
        {
            UserInfo myData2 = UserInfo.getMyInfo();
            if (myData2 != null) 
            {
                int highScore2 = counter.getScore();
                counterShop.score=counterShop.score+highScore2;
                
                myData2.setInt(5,counterShop.score);
                myData2.store();
            }
        }
New code:
        if(UserInfo.isStorageAvailable()) 
        {
            UserInfo myData = UserInfo.getMyInfo();
            if (myData != null) 
            {
                int highScore = counter.getScore();
                if (highScore>myData.getScore())
                {
                    myData.setScore(highScore);
                }
                counterShop.score += highScore;
                    
                myData.setInt(5,counterShop.score);
                myData.store();
            }
        }
Roshan123 Roshan123

2021/12/22

#
Super_Hippo wrote...
Anyway, this might fix it: New code:
        if(UserInfo.isStorageAvailable()) 
        {
            UserInfo myData = UserInfo.getMyInfo();
            if (myData != null) 
            {
                int highScore = counter.getScore();
                if (highScore>myData.getScore())
                {
                    myData.setScore(highScore);
                }
                counterShop.score += highScore;
                    
                myData.setInt(5,counterShop.score);
                myData.store();
            }
        }
YAY! It worked ....I think so But can u tell me the reason why u wrote
 if ( highScore>myData1.getScore())
        {
            myData1.setScore(highScore);
         }
mydata1.store();
instead of this
 if ( highScore>myData1.getScore())
        {
            myData1.setScore(highScore);
            myData1.store();
        }
You need to login to post a reply.