More Blocks

Let's call game.set_block(), using the locations from the previous lesson:

game.set_block(p1, 17)
game.set_block(p_up, 17)

Click 'run', and look at the 3D world screen, you got 2 brick blocks: one is on the ground, the other is on top of the first.

Let's continue to build more blocks. I will use different numbers for the second parameter, which represents the material of block we place:

game.set_block(p_right, 18)
game.set_block(p_left, 19)

game.set_block(p_front, 56)
game.set_block(p_back, 59)

Do you see the results? You built some virtual structures with Python!

Call game.set_block() without position variable

So far we have always used a position variable (e.g. p_left or p_up) to call game.set_block(). But in this simple example, we can skip these variables since they are only used once:

game.set_block(Position(0, 3, -20), 1)

This works the same as assigning Position(0, 3, -20) to a variable and then use it as the first parameter to game.set_block().

Run the code, you should see a black block on top of the bricks.

Clean up the screen

Sometimes you might want to clean up all the structures you have built in the game or the content in the console window. You can either reload the browser window, or use the following code:

# Clear the console window
game.clear_console()

# Clear the game screen
game.clear_screen()

results matching ""

    No results matching ""