-4

How do I get rid of the blank line after an if statement like this?

>>> import mcpi.minecraft as minecraft
>>> import mcpi.block as block
>>> import time as time
>>> mc=minecraft.Minecraft.create()
>>> mc
<mcpi.minecraft.Minecraft instance at 0x767e2f58>
>>> block.GOLD_BLOCK=block.GOLD_BLOCK
>>> while True:
...     x,y,z=mc.player.getPos()
...     block_beneath=mc.getBlock(x,y-1,z)
...     if block_beneath != block.GOLD_BLOCK:
...             mc.setBlock(x,y-1,z,block.GOLD_BLOCK)
... 

After the ..., it goes to a blank line and won't let me put in anymore code.

This seems like a stupid question to ask, and it is probably an easy fix, but I don't know how to fix it. Thanks for all the help!

Thanks for all your answers! I'll look over it and try the things you guys said to do! :D

EofTheN
  • 13
  • 3
  • I did after the ..., and it just went blank – EofTheN Jul 02 '17 at 18:40
  • 1
    use an editor like VIM to write your code and then run it using the command prompt. It seems that you started python in the cmd and then started writing your code. You can open the cmd and type: `vim file.py`. This will create a python file with name file and then you can run it using: `python file.py` – seralouk Jul 02 '17 at 18:42

2 Answers2

3
while True:

This starts an infinite loop. When you press Enter after the last ..., the loop starts to run and will never quit. The REPL must finish executing the code you enter before it will allow you to enter any more code.

Most likely you need to put your code in a file. This allows you to more easily edit your code to fix changes or add functionality. I suggest you learn more about saving python code in a file.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Is there a way to enter more code after that? Or do I have to open a new window and repeat the process all over again to do other things? – EofTheN Jul 02 '17 at 18:41
  • 1
    @EofTheN. The REPL must finish executing the code you give it before it will allow you to type any more code. If you open a new window, the code you enter there will be completely independent of the first window. An infinite loop indicates that you are likely doing something wrong. You most likely need to figure out a different way to accomplish what you want. – Code-Apprentice Jul 02 '17 at 18:44
0

First of all, why are you doing it in the shell? If you have IDLE, just make a new file by putting in Ctrl + N in the shell.

And here's the code in a new file to copy and paste :):

import mcpi.minecraft as minecraft
import mcpi.block as block
import time as time
mc=minecraft.Minecraft.create()
block.GOLD_BLOCK=block.GOLD_BLOCK
while True:
    x,y,z=mc.player.getPos()
    block_beneath=mc.getBlock(x,y-1,z)
    if block_beneath != block.GOLD_BLOCK:
        mc.setBlock(x,y-1,z,block.GOLD_BLOCK)

I hope I help with this! :)

JBoy Advance
  • 78
  • 1
  • 13