Set Up CodeCraft

When you start this lesson, the code editor should show you the following code:

# Chapter 2: Build blocks in CodeCraft
from codecraft import Game, Position
game = Game()
materials = game.materials

These 3 lines of code (excluding the comment line) give you access to the CodeCraft 3D game world. Please don't delete or change them. Each time you start a new CodeCraft file, you'll need to have these lines at the top of your program.

Why do we need that code?

You do not have to understand these lines to continue with the next lesson, but I'll explain a little bit in case you're curious.

Line 2: from codecraft import Game, Position imports the Game and Position classes from the codecraft module into our program so we can use them later in the file. In Python, a module may contain functions or data types that have been defined by others. You can use them to interact with some system, like the computer screen, a web site, or a USB drive. In our case, it's the CodeCraft game.

Line 3: game = Game() creates an object of the Game class so we can access its attributes, like functions and variables. The object is assigned to a variable named game.

Line 4: materials = game.materials reads some data from the game object using dot notation, which is always in the format of object.item. Here we access an object variable, game.materials, and assign this to a new variable in our application, also named materials.

results matching ""

    No results matching ""