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

2012/8/19

On 'platforms of meh by steved'

1
2
danpost danpost

2012/8/19

#
I believe I found the UserInfo problem. Your method 'saveLevel' was getting an empty string for level, because the method 'getLevels' in your 'levelSelect' class was not saving any changes to the string. Below, you will see how line 9 changes the UserInfo object, so line 10 can save the change. Also, I changed line 7 to the appropriate check.
public void getLevels()
{
    if(UserInfo.isStorageAvailable())
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        level = myInfo.getString(1);
        if(level == "") // UserInfo default for String value
        {
            myInfo.setString(1,level); // this changes the UserInfo object
            myInfo.store(); // this stores the changes
        }
    }
    else 
    {
        level = "xxxxxxxxxxxxxxxxxxxx";
    }
}
The same problem arises in the 'saveLevel' methods in all your 'map##' worlds. Changeyour 'saveLevel' methods to the following (using the appropriate 'level' strings, of course):
public void saveLevel()
{
    if(UserInfo.isStorageAvailable())
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        String level = myInfo.getString(1);
        if (level.charAt(0) == 'o')
        {
            myInfo.setString(1, "xooooooooooooooooooo"); // key change
            myInfo.store();
        }
    }
}
This should fix it (after un-commenting the calls to these methods). Post back if any problems. BTW, I did realized that there was no problem with what you were storing. That if a player re-did a previous level, no problems will arise.
steved steved

2012/8/20

#
Just tried to use your code for the level select and when I had a name set for my player (the ctrl-shift-p thing) it gave me that same error where my sting has no value?? Same with the worlds... Apperently it doesn't think there is anything in the strings?
danpost danpost

2012/8/20

#
Yeah, I did not catch the fact that your 'levelSelect' instance String field 'level' was being re-assigned by the 'myInfo.getString(...)'. (1) remove the declared field 'String level = "oooooooooooooooooooo";' (2) change your 'levelSelect' constructor to the following:
public levelSelect()
{    
    super(900, 600, 1);
    addObject(new BackButton(), 100, 550);
    addWorlds(getLevels());
}
(3) change your 'getLevels()' method to the following:
public String getLevels()
{
    if(UserInfo.isStorageAvailable())
    {
        UserInfo myInfo = UserInfo.getMyInfo();
        String level = myInfo.getString(1);
        if(level == "")
        {
            level = "oooooooooooooooooooo";
            myInfo.setString(1,level);
            myInfo.store();
        }
        return level;
    }
    return "xxxxxxxxxxxxxxxxxxxx";
}
(4) begin your 'addWorlds' method with 'public void addWorlds(String level)' Now it will have something in the String.
danpost danpost

2012/8/20

#
To simplify your 'addWorlds' method, use the following:
public void addWorlds(String level)
{
    for (int i = 0; i < 20; i++)
    {
        if ('x' == level.charAt(i))
        {
            Buttons btn;
            int w = (i / 5) + 1;
            int n = (i % 5) + 1;
            switch(w)
            {
                case 1: btn = new world1(n); break;
                case 2: btn = new world2(n); break;
                case 3: btn = new world3(n); break;
                case 4: btn = new world4(n); break;
            }
            addObject(btn, 425 + 75 * n, 50 + 100 * w);
            addObject(new levelText(w, n),425 + 75 * n, 80 + 100 * w);
        }
    }
}
steved steved

2012/8/21

#
Still getting this error report: java.lang.StringIndexOutOfBoundsException: String index out of range: 0 That is the first line of it. Try compiling it then clicking the level select button and you will see what I mean
danpost danpost

2012/8/21

#
This is what I have in the 'levelSelect' class, and it seems to work fine.
import greenfoot.*;

public class levelSelect extends World
{
    public levelSelect()
    {    
        super(900, 600, 1);

        addObject(new BackButton(), 100, 550);
        addWorlds(getLevels());
    }

    public String getLevels()
    {
        String level;
        if(UserInfo.isStorageAvailable())
        {
            UserInfo myInfo = UserInfo.getMyInfo();
            level = myInfo.getString(1);
            if(level == "")
            {
                level = "oooooooooooooooooooo";
                myInfo.setString(1,level);
                myInfo.store();
            }
        }
        else 
        {
            level = "xxxxxxxxxxxxxxxxxxxx";
        }
        return level;
    }

    public void addWorlds(String level)
    {
        for (int i = 0; i < 20; i++)
        {
            if ('x' == level.charAt(i))
            {
                buttons btn = null;
                int w = (i / 5) + 1;
                int n = (i % 5) + 1;
                switch(w)
                {
                    case 1: btn = new world1(n); break;
                    case 2: btn = new world2(n); break;
                    case 3: btn = new world3(n); break;
                    case 4: btn = new world4(n); break;
                }
                addObject(btn, 425 + 75 * n, 50 + 100 * w);
                addObject(new levelText(w, n),425 + 75 * n, 80 + 100 * w);
            }
        }
    }
}
Maybe you should delete the 'storage.csv' file for this scenario and have it start a fresh one, as the old one may be corrupted by previous code.
danpost danpost

2012/8/21

#
Actually, you should post the whole error message. It tells you exactly where to look.
steved steved

2012/8/21

#
Thank you! It must have been a corrupted csv file as it seems to work fine now that I have deleted it. The worlds also all work fine now. The game will be updated in a few minutes - and level select fill finally work :D.
danpost danpost

2012/8/22

#
Apparently, the on-site file is also corrupted. Better change line 8 in your 'getLevels' method from 'if (level == "")' to 'if (level.length() != 20)' to cover all possibilities.
steved steved

2012/8/23

#
Ok I'm doing that right now. Again, thanks for all of the help.
steved steved

2012/8/23

#
Do you have any idea why it is only loading level 1? I've looked at the code for each level and am not sure. Also I only partially understand the loading thing you gave me. Could it be that?
danpost danpost

2012/8/23

#
I do not know, your source is not available right now. I doubt it is what I gave you since I have it working fine on my laptop.
steved steved

2012/8/24

#
Well it was working on my laptop too... I might just change it to something simpler... I had also tried for loops before I did user info and even though it should have worked it didn't.
danpost danpost

2012/8/24

#
If you supply the source, even for just a few minutes, I can download what you have and take a look. :?
steved steved

2012/8/24

#
I will upload it. The source should be up anyways. Thanks for looking at it.
There are more replies on the next page.
1
2