0

I have two scripts for a game I just started, one is the main game and the other is meant to show 3 images when the first script is ran, so when I run the first script (mainGame.py) it should run using classes and functions the second script (startUp.py) and then startUP would show a images with the game title and a created by screen and then I would have it go on to the game menu. but of course its not working, here is my code for the main game:

import pygame, random, math, sys, os, time
import startUp
from pygame.locals import *
pygame.init()

while True:

    #quit button 
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    startUp.Begin.Run()

code for second script (startUp.py):

import pygame, time
from pygame.locals import *
pygame.init()

class Begin(self):

    def __init__(self):
        self.screenA = "createdbyscreen.png"
        self.screenB = "powerdbyscreen.png"
        self.screenC = "gamelogoscreen.png"
        self.blackscreen = "blackSreen.png"

        self.screen = pygame.display.set_mode((1440, 720), 0, 32)

        self.startscreenA = pygame.image.load(screenA).convert()
        self.startscreenB = pygame.image.load(screenB).convert()
        self.startscreenC = pygame.image.load(screenC).convert()
        self.blackscreen = pygame.image.load(blackscreen).convert()

    def Run(self):
        while True:
           #starting imagers
            self.screen.blit(blackscreen, (0, 0))
            self.timeLeft = pygame.time.get_ticks()
            print(self.timeLeft)
            if self.timeLeft < 3500:
                self.self.screen.blit(self.startscreenA, (480, 120))
            if self.timeLeft > 4000 and self.timeLeft < 7500:
                self.screen.blit(self.startscreenB, (480, 120))
            if self.timeLeft > 8000 and self.timeLeft < 11150:
                self.screen.blit(self.startscreenC, (480, 120))

            pygame.display.update()

then if it helps then here are the error messages:

first script:

Traceback (most recent call last):
  File "C:\Users\claude\Desktop\game\dnagame.py", line 2, in <module>
    import startUp
  File "C:\Users\claude\Desktop\game\startUp.py", line 5, in <module>
    class Begin(self):
NameError: name 'self' is not defined

and the second:

Traceback (most recent call last):
  File "C:/Users/claude/Desktop/game/startUp.py", line 5, in <module>
    class Begin(self):
NameError: name 'self' is not defined

thank you for your time and help!

2 Answers 2

2
class Begin(self):

You should inherit from object

class Begin(object):

You also need to make an instance

begin = startUp.Begin()
begin.Run()
Sign up to request clarification or add additional context in comments.

3 Comments

I changed self to object and I just got a error saying Run() missing 1 required positional argument: 'object'
@user3342999 look again
@user3342999 did you replace startUp.Begin.Run() with my snippet?
0

A class must inherit from object and not self:

class Begin(object):

self is the convention name used for the first argument of instance methods, which's a reference to the instance itself.

1 Comment

Please don't include ^ in your code snippet. Its confusing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.