The place to post if you need help or advice

Moderators: ChriThor, LXF moderators


Postby RyanF109 » Mon Oct 22, 2012 2:55 pm

I have kept all of my coding academy tutorials and today I started the process of working my way through them.

I decided to play around with python and I am trying to create code that generates a random colour for the screen fill every time you click the mouse. But after spending a while fixing indentation errors now when I run it, it just quits with no error, as if one of the returns are being executed. Can anybody see any obvious errors in my code?

Code: Select all

#import modules
import pygame
import os,random

#define colour settings class
class colourset():

   def __init__(self):
      """ colour settings """

   def gencolour(self):

      self.r = random.randint(0,255)
      self.g = random.randint(0,255)
      self.b = random.randint(0,255)
      return self

   def colourscreen(self,colour):
      self.screensize = (800,600)
          self.screen = pygame.display.set_mode(self.screensize)
          pygame.display.set_caption('Random Colour')

          self.backdrop = pygame.Surface(self.screensize)

      #refresh the screen by drawing everything again
      #redrawthe background
      self.screen.blit(self.backdrop, (0, 0))

      #flip the buffer

def main():
   """the main game logic"""

   #Initialize Everything

   colourinst = colourset()
   colour = colourinst.gencolour()
   clock = pygame.time.Clock()

   # control loop

   while 1:
      #adjust this timer to make the game harder or easier

      #check what events Pygame has caught
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
          elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
          elif event.type == pygame.MOUSEBUTTONDOWN:
         #button means mouse click
         colourinst = colourset()
         colour = colourinst.gencolour()
         clock = pygame.time.Clock()

   if __name__ == '__main__':
Posts: 16
Joined: Mon Jan 02, 2012 7:53 pm

Postby RyanF109 » Mon Oct 22, 2012 9:54 pm

I fixed it. It was an indentation error. I'm not used to indentation being so important!
Posts: 16
Joined: Mon Jan 02, 2012 7:53 pm

Postby lok1950 » Mon Oct 22, 2012 10:44 pm

If you are using gedit or kwrite you can set syntax checking for a variety of languages.

Enjoy the Choice :)
LXF regular
Posts: 1134
Joined: Tue May 31, 2005 5:31 am
Location: Ottawa

Return to Help!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest