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

2012/7/9

This method seems to decide not to execute past a certain point

darkmist255 darkmist255

2012/7/9

#
Another question that might solve itself shortly after posting, but I've set up a little debugging thing to let me know how far this gets before stopping. The problem is that it executes correctly when loading the tiles, but stops before actually placing them in the world. The game does not freeze at all, the player can still move around and do things, there's just no tiles loaded anywhere.
    public void addTile(String tileType, String tileData)
    {
        String tileXst = tileData;
        tileXst = tileXst.substring(0, tileXst.indexOf(','));
        String bufLineText = tileData.substring(tileXst.length() + 1);
        String tileYst = bufLineText;
        
        int tileX = Integer.parseInt(tileXst);
        int tileY = Integer.parseInt(tileYst);
        
        List<String> tileInfo = new ArrayList();
        String working = new String();
        
        System.out.println("pre-tileY");
        if(tileYst.contains(","))
        {
            tileYst = tileYst.substring(0, tileYst.indexOf(','));
            bufLineText = tileData.substring(tileYst.length() + 1);
            working = bufLineText;
        }
        System.out.println("post-tileY");
        for(int i = 0; i < 50; i++) //50 times max
        {
            System.out.println("pre-break1");
            working = working.substring(0, working.indexOf(','));
            System.out.println("pre-break2");
            tileInfo.add(working);
            System.out.println("pre-break3");
            bufLineText = tileData.substring(working.length() + 1);
            System.out.println("pre-break4");
            if(!bufLineText.contains(","))
            {
                tileInfo.add(bufLineText);
                break;
            }
        }
        System.out.println("post-break");
        
        if(tileTypes.indexOf(tileType) >= 0)
        {
            try {
                worldObject tileToAdd = (worldObject)(tileClasses.get(tileTypes.indexOf(tileType)).newInstance());
                addObject(tileToAdd, tileX*PersistentStorage.tileSize, tileY*PersistentStorage.tileSize);
                tileToAdd.loadData(tileInfo);
                tileToAdd.partOfWorld = true;
            }
            catch(Exception e)
            {
                System.err.println("Caught Exception: " + e.getMessage());
            }
        }
    }
The terminal says "pre-tileY post-tileY pre-break1 pre-tileY post-tileY pre-break1" etc... Meaning it's only reaching pre-break1. Is the line "working = working.substring(0, working.indexOf(','));" causing problems? Any help is appreciated.
darkmist255 darkmist255

2012/7/9

#
Resolved... It seems as though every time I post something I end up solving it 20 minutes later. I reorganized it so the break statement came BEFORE line 24. I had to check first, not last.
danpost danpost

2012/7/9

#
That line should not be causing a problem, unless 'working' does not contain a ','. And if that was the case, you would be getting an exception for array index out of bounds. Try adding 'System.out.println("working = \"" + working + "\"");' before that statement and see if following the logic with what is returned helps. Post back the results. Glad you found it.
You need to login to post a reply.