I've been writing a game for a hobby/submitting it as a final project, cool stuff. But I've recently run into a mind-boggling issue that I have no idea how or why it happens.
This method is to draw a box for the game, but whenever it runs the console output seems to add more and more characters to the script. I tried to debug it, but so far it turns out I'm not a very good debugger.
def drawModule(selections, selected):
'''Draws a text box based on the inputs given'''
str1 = ""
str2 = ""
str3 = " "
str4 = ""
str5 = ""
modList = selections
print id(modList)
print id(selections)
for i in range(len(modList)):
if i == selected:
modList[i] = "| " + modList[i] + " | "
else:
modList[i] = "# " + modList[i] + " # "
str3 += modList[i]
print selections
print modList
for i in range(len(modList)):
str1 += " "
str2 += " "
str4 += " "
str5 += " "
for letter in range(len(modList[i]) - 2):
if letter == 0 or letter == (len(modList[i]) - 3):
if i == selected:
str1 += "|"
str2 += "|"
str4 += "|"
str5 += "|"
else:
str1 += "#"
str2 += "#"
str4 += "#"
str5 += "#"
else:
if i == selected:
str1 += "-"
str2 += " "
str4 += " "
str5 += "-"
else:
str1 += "#"
str2 += " "
str4 += " "
str5 += "#"
sys.stdout.write(str1 + "\n" + str2 + "\n" + str3 + "\n" + str4 + "\n" + str5)
The script calling this method is for the beginnings of the combat system in my game. It's a rogue-like isaac-like whateverthehell made out of ASCII text, not that it matters.
UNFINISHED
def combat():
'''Runs combat seperately from the selection menu'''
inCombat = True
print "You've started combat!"
time.sleep(1)
options = ["attack", "guard", "inventory", "flee"]
position = 0
clear()
while inCombat:
if msvcrt.kbhit():
clear()
key = msvcrt.getch()
print options
if ord(key) == 100:
position +=1
drawModule(options, position)
elif ord(key) == 97:
position -= 1
drawModule(options, position)
elif ord(key) == 27:
break
I'm still losing my mind over this, any solution would be amazing. Also, I'm not great at this, so if you find something I can do better, I'd love to know more!
Console Output when run multiple times:
138650760
138650760
['# attack # ', '| guard | ', '# items # ', '# flee # ']
['# attack # ', '| guard | ', '# items # ', '# flee # ']
########## |-------| ######### ########
# # | | # # # #
# attack # | guard | # items # # flee #
# # | | # # # #
########## |-------| ######### ########
-------------------------Second Time----------------------
138650760
138650760
['# # attack # # ', '| | guard | | ', '# # items # # ', '# # flee # # ']
['# # attack # # ', '| | guard | | ', '# # items # # ', '# # flee # # ']
################ |-------------| ############### ##############
# # | | # # # #
# # attack # # | | guard | | # # items # # # # flee # #
# # | | # # # #
################ |-------------| ############### ##############
This trend continues some insubordinate amount of time.