-1

So I'm working on a rendering system for a small Python game I'm making and I found that when I print the Render's Dictionary that I use to store tile renders, I found that only the fourth tile of every row is actually rendered.I intended for it to output what it currently outputs to every fourth tile to every tile within the render distance but that sadly is not working. My code and output is as follows:

main:

import RenderGame
import CreateWorld

global Map
Rows = {}


#Start.start()
#MainMenu.listMenu_Main00()

Map = CreateWorld.createLandscape(5, 5)
#print Map

Render = RenderGame.render(Map, 0, 0, 2, 2)
print Render

#random.seed("z12")
#print random.randint(1, 5)

world generation:

global Map
Map = {}
Map["Rows"] = {}


#The Process of Generating a Blank Map xAxis long and zAxis wide
def createLandscape(xAxis, zAxis):
    #Sets the amount of createdRows to 0
    createdRows = 0

    #Calls createRow() the amount of times that the Map is Long
    while createdRows < xAxis:
        createRow(createdRows, zAxis)
        createdRows += 1

    return Map

#The Process of Generating a Blank Map Row zAxis Wide and with a Row Number of RowsCreated
def createRow(RowsCreated, zAxis):
    #Sets the variable "createdTiles" to 0
    createdTiles = 0

    #Sets the variable "createdRows" to the parameter "RowsCreated"
    createdRows = RowsCreated

    #Creates a Row within the dictionary "Rows"
    Map["Rows"]["Row %s" % createdRows] = {}

    #Calls createTile() the amount of times that the Row is wide
    while createdTiles < zAxis:
        createTile(createdRows, createdTiles)
        createdTiles += 1

#The Process of Generating a Blank Map Tile in the 
def createTile(RowsCreated, TilesCreated):  
    #Sets the variable "createdRows" to the parameter "RowsCreated"
    createdRows = RowsCreated

    #Sets the variable "createdTiles" to the parameter "TilesCreated"
    createdTiles = TilesCreated


    Map["Rows"]["Row %s" % createdRows]["Tile %s" % createdTiles] = {}
    Map["Rows"]["Row %s" % createdRows]["Tile %s" % createdTiles]["Type"] = "Null"

renderer:

global Render

Render = {}

def render(Map, SelectedRow, SelectedTile, xDistance, zDistance):
    #Sets the variable "createdRows" to the parameter "RowsCreated"
    rowSelected = SelectedRow
    tileSelected = SelectedTile

    if checkSelection(Map, SelectedRow, tileSelected):
        renderMap(Map, rowSelected, tileSelected, xDistance, zDistance)
        return Render
        #DisplayGame.displayRender(Render, xDistance, zDistance)
    else:
        print "Readjusting Selection"
        rowSelected = 0
        tileSelected = 0


def checkSelection(Map, SelectedRow, SelectedTile):
    #Make sure the Map has Rows
    if "Rows" in Map:
        #Make sure the Rows has the Selected Row
        if ("Row %s" % SelectedRow) in Map["Rows"]:
            #Make sure the Selected Row has the Selected Tile
            if ("Tile %s" % SelectedTile) in Map["Rows"]["Row %s" % SelectedRow]:

                return True

            #Give Error Message if I cluck up
            else:
                print "   [DEBIG]: The Key that represents to Selected Tile cannot be found in the Dictionary that represents the Selected Row   " 
        #Give Error Message if I cluck up
        else:
            print "   [DEBIG]: The Key that represents to Selected Row cannot be found in the Dictionary \"Rows\"   "
    #Give Error Message if I cluck up
    else:
        print "   [DEBIG]: The Key \"Rows\" cannot be found in the Dictionary \"Map\"   "

def renderMap(Map, SelectedRow, SelectedTile, xDistance, zDistance):
    rowRendersCreated = 0

    while rowRendersCreated < 1 + (zDistance * 2):
        createRowRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, rowRendersCreated)
        rowRendersCreated += 1

def createRowRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, CreatedRowRenders):
    rowRendersCreated = CreatedRowRenders
    tileRendersCreated = 0


    while tileRendersCreated < 1 + (xDistance * 2):
        Render["Row %s" % rowRendersCreated] = {}
        createTileRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, rowRendersCreated, tileRendersCreated)
        tileRendersCreated += 1


def createTileRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, CreatedRowRenders, CreatedTileRenders):
    rowRendersCreated = CreatedRowRenders
    tileRendersCreated = CreatedTileRenders

    Render["Row %s" % rowRendersCreated]["Tile %s" % tileRendersCreated] = ""

    if Map["Rows"]["Row %s" % rowRendersCreated]["Tile %s" % tileRendersCreated]["Type"] == "Null":
        Render["Row %s" % rowRendersCreated]["Tile %s" % tileRendersCreated] = "--------"

output:

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
{'Row 1': {'Tile 4': '--------'}, 'Row 0': {'Tile 4': '--------'}, 'Row 3': {'Tile 4': '--------'}, 'Row 2': {'Tile 4': '--------'}, 'Row 4': {'Tile 4': '--------'}}
>>>

Anyone have any idea why this is happening?

  • Questions seeking debugging help ("**why isn't this code working?**") must include the **desired behavior**, a **specific** problem or error and the **shortest** code necessary to reproduce it **in the question itself**. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). ***TL;DR***: Shorten your code to the minimum necessary to reproduce the problem, and put it in the question itself. Don't link to external sites. – MattDMo Mar 25 '15 at 22:10
  • It's very unlikely that someone will dig through the code on pastebin, so I've added it to the original question. You will need to cut that down to the relevant pieces - it's a lot to go through. – Celeo Mar 25 '15 at 22:11
  • @Celeo you don't need to add it to the question, let the OP do it, and make an MCVE in the meantime. – MattDMo Mar 25 '15 at 22:12
  • @Celeo you also only included 1 file. Just roll back your edit and let the OP deal with it. – MattDMo Mar 25 '15 at 22:14
  • Sorry, still new to the site, will not use links in any future questions. Funny thing is that usually sites like to keep posts tidy with PasteBin. The more you know I guess – 1SDANTheMan Mar 25 '15 at 22:16
  • @1SDANTheMan Stack Overflow/Exchange prefers you to include the code in the post rather than as a Pastebin because it means the question is still useful if the link goes away. It helps keep questions useful in the long-term. – alexwlchan Mar 25 '15 at 22:27
  • Please read through the [help] to learn more about Stack Overflow and what is expected here. Also, did you read my previous comment? You're showing code that won't run (at least the way you expect it to), you're referencing modules/functions/classes/whatever that you haven't included in the question, you're reassigning values to global variables that are originally of different types, and you **haven't** condensed things to a **short**, **self-contained**, **runnable** example that clearly illustrates the problem at hand. Please do that. – MattDMo Mar 25 '15 at 22:41
  • Oops, I actually thought that I removed those references. As for the short part, this is about all that I can do. Hopefully that helps – 1SDANTheMan Mar 25 '15 at 23:02

1 Answers1

1

I haven't tried to create separate files for all your code snippets yet, but I think I can spot the problem without having to run the code. In createRowRender you reset the dictionary for each row every time you increment the tile count:

while tileRendersCreated < 1 + (xDistance * 2):
        Render["Row %s" % rowRendersCreated] = {}
        createTileRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, rowRendersCreated, tileRendersCreated)
        tileRendersCreated += 1

I think that should be something like:

while tileRendersCreated < 1 + (xDistance * 2):
    rowName = "Row %s" % rowRendersCreated
    if not rowName in Render:
        Render[rowName] = {}
    createTileRender(Map, SelectedRow, SelectedTile, xDistance, zDistance, rowRendersCreated, tileRendersCreated)
    tileRendersCreated += 1
Marius
  • 58,213
  • 16
  • 107
  • 105
  • Thank you very much, that fixed the problem. I actually didn't think that code would have that effect, but now I can't think of a way why it wouldn't. – 1SDANTheMan Mar 25 '15 at 23:17