0

here is my problem - I am trying to re-build KNIGHT’S QUEST game based on book "Beginner's Step-by-Step coding course" (Download the complete Coding Course Resource Pack). And I have got Error message: NameError: name 'Actor' is not defined. I also read related one-year old article about the same problem here: Name 'Actor' is not defined and added to my code this line: from pgzero.builtins import Actor, animate, keyboard, but then I got this error message: error: cannot convert without pygame.display initialized. The same error occurs even when I try to run original game provided by issuer (I downloaded it without modification). This is my code where error occurs:

import pgzrun
..
..
def screen_coords(x, y):
..
def draw_background():
..
def draw_scenery():
..
def setup_game():
    global player
    player = Actor('player', anchor=('left', 'top'))
    for y in range(grid_height):
        square = MAP[y][x]
        if square == 'P':
            player.pos = screen_coords(x, y)
def draw_actors():
    player.draw()

def draw():
    draw_background()
    draw_scenery()
    draw_actors()

setup_game()
pgzrun.go()

How should I modify it to get it running? Thanks!

wotesi
  • 319
  • 1
  • 3
  • 15

3 Answers3

0

Problem partially solved - code somehow runs on Windows machine (Anaconda/Spyder) (it does not run on Ubuntu-Anaconda/Spyder machine), although it runs with issues - when I run it inside Spyder, it gives error message and does not compile, but when I test it and run from Terminal Python + name of the file.py it executes well.

wotesi
  • 319
  • 1
  • 3
  • 15
0

Try importing the following:

from pgzero.builtins import Actor
lime
  • 801
  • 8
  • 21
0

I tested KNIGHT’S QUEST.

I added :

from pgzero.builtins import  Actor, animate, keys

from pgzero import clock

to quest.py flie. Then it works well in spyder editor.

Ruli
  • 2,592
  • 12
  • 30
  • 40
  • Please avoid adding multiple answers to a single question, instead, you can always use edit button under the answer to add additional information. – Ruli Dec 10 '20 at 21:17