Sign in to follow this  
K1NNY

I need help on why this isn't working

Recommended Posts

I'm trying to make it where i display my main starting screen with a while loop and it doesn't seem to be working. If i blit the pictures normally outside of the loop it works, but just simply having the loop stops the program from even going. This is my while loop:

[source lang="python"]#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
game == True[/source]
"game" being another loop that simply fills the screen white(for testing, later this will initiate the game).

Here's the whole code:

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

pygame.init()

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

#variables
x = randint.x
year = 2011
p = pplrty.p

#get colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)

#get display stuff
DISPLAY = pygame.display.set_mode((640,480))
pygame.display.set_caption('Program')

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

#make words
textObj1 = fontObj1.render('Hit Enter', True, RED)
RectObj1 = textObj1.get_rect()
RectObj1.center = (315, 240)

#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))


#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
game == True

while game:
DISPLAY.fill(WHITE)


#Main Loop
while True:

for event in pygame.event.get():

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

pygame.display.update()

[/source]

The game is going to be a simple game with a simple gui and is in its first stages so certain things are not there, but it was working until i put the blit images in the loop.

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1349112411' post='4985801']
Did you mean to use == instead of = for [tt]start_screen == False[/tt]?
[/quote]

Yes that was a mistake, i'll fix it when i get back to working on it.

Share this post


Link to post
Share on other sites
That actually didn't work either. Am i using the while loop wrong? when i replaced the "=" with "==" it errored and said "start_screen is not defined"

EDIT:

I fixed it, i was forgetting to call pygame.display.update Edited by K1NNY

Share this post


Link to post
Share on other sites
You mistake his meaning. Your initialization of start_screen needs to remain [b]start_screen=True[/b], but in your conditionals [b]if event.key==pygame.K_RETURN[/b] you need to change [b]start_screen==False[/b] and [b]game==True[/b] to [b]start_screen=False[/b] and [b]game=True[/b]. Because as it stands, you are not assigning to those values you are just comparing them to True or False.

Share this post


Link to post
Share on other sites
[size=5][sub][quote name='K1NNY' timestamp='1349189120' post='4986057']
That actually didn't work either. Am i using the while loop wrong? when i replaced the "=" with "==" it errored and said "start_screen is not defined"
[/quote][/sub]
[sub]That's partially because you corrected in the wrong direction. Line 42 in your post above (the "entire code" section) is fine. It declares and defines the start_screen variable. The problem is lines 53 and 54. Those should be assignments and not boolean checks, so replace their =='s with a single =.[/sub][/size]

[size=5][sub]Edit: slightly too slow. Ah well.[/sub][/size] Edited by BCullis

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this