While loop trouble

Started by
11 comments, last by K1NNY 11 years, 6 months ago
I'm Unable to see the second part of the code. I had this problem before, try an replace all <= into < because the code tags break when they see <= for some reason. It is also better for help_credits to be compared to zero like this: help_credits <= 0 because this is safer than help_credits == 0. I'm going to have to see the rest of the code before I can tell why it is unresponsive.
Advertisement
Here is the full code (excluding all the text surfaces) all >= have been replaced with >:

[source lang="python"]import pygame, random
import sys
from pygame.locals import *

pygame.init()

FPS = 30
fpsClock = pygame.time.Clock()

#variables
year = 2011
p = 50
pop = 100000
help_credits = 5

#definition time



#get colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
DARKRED = (128, 0, 0)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)

#get display stuff
DISPLAY = pygame.display.set_mode((640,480))
pygame.display.set_caption('UTOPIA')
pygame.mouse.set_visible(True)

#create fonts
fontObj1 = pygame.font.Font('freesansbold.ttf', 16)
fontObj2 = pygame.font.Font('freesansbold.ttf', 12)


#make words


#get images
title = pygame.image.load('title.png')
stitle = pygame.transform.scale(title, (264, 64))

bg = pygame.image.load('bg.png')
sbg = pygame.transform.scale(bg, (640, 480))
gbg = pygame.image.load('Game_bg.png')
help_bg_root = pygame.image.load('help_bg.png')
help_bg = pygame.transform.scale(help_bg_root, (640, 480))



#Menu screen
start_screen = True

while start_screen:
DISPLAY.blit(sbg, (0, 0))
DISPLAY.blit(stitle, (188, 10))
DISPLAY.blit(textObj1, RectObj1)


for event in pygame.event.get():

if event.type == pygame.KEYDOWN:

if event.key == pygame.K_RETURN:
start_screen = False
instructions = True

if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()





#################################Game loop######################################



#Main Loop


while True:
if help_credits > 1:
help_events = True

elif help_credits == 0:
help_events = False

while instructions:
DISPLAY.blit(sbg, (0, 0))
DISPLAY.blit(instructions_1, (100, 36))
DISPLAY.blit(instructions_2, (9, 54))
DISPLAY.blit(instructions_3, (175, 72))
DISPLAY.blit(instructions_4, (85, 100))
DISPLAY.blit(instructions_5, (78, 118))
DISPLAY.blit(instructions_6, (40, 136))
DISPLAY.blit(instructions_7, (260, 154))
DISPLAY.blit(instructions_8, (310, 154))
DISPLAY.blit(instructions_9, (350, 154))


for event in pygame.event.get():

if event.type == pygame.KEYDOWN:

if event.key == pygame.K_RETURN:
instructions = False
game = True

if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

elect_new = False
lower_int = False
cut_taxes = False


while game:
x = random.randint(1, 10)
y = random.randint(1, 3)



show_year = fontObj1.render(str(year), True, BLACK)
show_pop = fontObj1.render(str(pop), True, BLACK)


DISPLAY.blit(gbg, (0, 0))
DISPLAY.blit(controls_1, (225, 50))
DISPLAY.blit(controls_2, (225, 66))
DISPLAY.blit(controls_3, (225, 82))
DISPLAY.blit(controls_4, (225, 100))




for event in pygame.event.get():

#the pplrty determiner
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
year += 1
print year
print x
print p
DISPLAY.blit(show_year, (563, 400))
DISPLAY.blit(show_pop, (400, 400))

if x == 1:
DISPLAY.blit(events_1, (45, 50))
DISPLAY.blit(events_1_2, (45, 66))
DISPLAY.blit(events_1_3, (45, 82))
p += 2
if x == 2:
DISPLAY.blit(events_2, (45, 50))
DISPLAY.blit(events_2_2, (45, 66))
DISPLAY.blit(events_2_3, (45, 82))
p -= 2
if x == 3:
DISPLAY.blit(events_3, (45, 50))
DISPLAY.blit(events_3_2, (45, 66))
DISPLAY.blit(events_3_3, (45, 82))
p -= 3
if x == 4:
DISPLAY.blit(events_4, (45, 50))
DISPLAY.blit(events_4_2, (45, 66))
DISPLAY.blit(events_4_3, (45, 82))
DISPLAY.blit(events_4_4, (45, 98))
DISPLAY.blit(events_4_5, (45, 114))
DISPLAY.blit(events_4_6, (45, 130))
p -= 5
if x == 5:
DISPLAY.blit(events_5, (45, 50))
DISPLAY.blit(events_5_2, (45, 66))
p -= 5
if x == 6:
DISPLAY.blit(events_6, (45, 50))
DISPLAY.blit(events_6_2, (45, 66))
DISPLAY.blit(events_6_3, (45, 82))
DISPLAY.blit(events_6_4, (45, 98))
DISPLAY.blit(events_6_5, (45, 114))
p -= 4
if x == 7:
DISPLAY.blit(events_7, (45, 50))
DISPLAY.blit(events_7_2, (45, 66))
DISPLAY.blit(events_7_3, (45, 82))
DISPLAY.blit(events_7_4, (45, 98))
p -= 4
if x == 8:
DISPLAY.blit(events_8, (45, 50))
DISPLAY.blit(events_8_2, (45, 66))
p -= 2
if x == 9:
DISPLAY.blit(events_9, (45, 50))
DISPLAY.blit(events_9_2, (45, 66))
DISPLAY.blit(events_9_3, (45, 82))
DISPLAY.blit(events_9_4, (45, 98))
p -= 6
if x == 10:
DISPLAY.blit(events_10, (45, 50))
DISPLAY.blit(events_10_2, (45, 66))
DISPLAY.blit(events_10_3, (45, 82))
p += 0

if p > 50 and p < 60:
DISPLAY.blit(pplrty_decent, (225, 400))
pop += 10000
elif p > 60 and p < 85:
DISPLAY.blit(pplrty_good, (230, 400))
pop += 30000
elif p > 85 and p < 100:
DISPLAY.blit(pplrty_great, (230, 400))
pop += 50000
elif p > 25 and p < 50:
DISPLAY.blit(pplrty_bad, (225, 400))
pop -= 10000
elif p < 25:
DISPLAY.blit(pplrty_awful, (225, 400))
pop -= 30000


pygame.display.update()


if event.type == QUIT:
pygame.quit()
sys.exit()

while help_events:

if p < 15 and y == 1:
game = False
elect_new = True
elif p < 15 and y == 2:
game = False
lower_int = True
elif p < 15 and y == 3:
game = False
cut_taxes = True


while elect_new:
DISPLAY.blit(help_bg, (0, 0))
DISPLAY.blit(elect_1, (165, 75))
DISPLAY.blit(elect_2, (165, 93))
DISPLAY.blit(elect_3, (165, 111))
DISPLAY.blit(yes, (300, 350))
DISPLAY.blit(under, (300, 350))
pygame.display.update()

for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_y:
DISPLAY.blit(enter, (285, 370))
p += 30
help_credits -= 1
elect_new = False
game = True


if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

while lower_int:
DISPLAY.blit(help_bg, (0, 0))
DISPLAY.blit(elect_1, (165, 75))
DISPLAY.blit(lower_int_1, (165, 93))
DISPLAY.blit(lower_int_2, (165, 111))
DISPLAY.blit(lower_int_3, (165, 129))
DISPLAY.blit(yes, (300, 350))
DISPLAY.blit(under, (300, 350))
pygame.display.update()

for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_y:
DISPLAY.blit(enter, (285, 370))
p += 30
help_credits -= 1
lower_int = False
game = True


if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

while cut_taxes:
DISPLAY.blit(help_bg, (0, 0))
DISPLAY.blit(elect_1, (165, 75))
DISPLAY.blit(cut_taxes_1, (165, 93))
DISPLAY.blit(cut_taxes_2, (165, 111))
DISPLAY.blit(cut_taxes_3, (165, 129))
DISPLAY.blit(yes, (300, 350))
DISPLAY.blit(under, (300, 350))



for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_y:
DISPLAY.blit(enter, (285, 370))
p += 30
help_credits -= 1
cut_taxes = False
game = True


if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

for event in pygame.event.get():

if event.type == QUIT:
pygame.quit()
sys.exit()

pygame.display.update()
[/source]
I thought hard on it overnight and fixed it this morning. Thanks for the help! smile.png

This topic is closed to new replies.

Advertisement