For Loops Nether Portal
compX44 opened this issue · comments
Hello @gilesknap
I'm doing the nether portal build in the loops section. I'm receiving an error that says minecraft:obsidian is not in list. The code works fine when I copy and paste it from the instructions into the terminal, but when I type it in myself, I get the error as shown
In [1]: pos = world.player.pos
In [2]: for x in range(4):
...: # bottom row
...: world.set_block(pos + Direction.EAST * x, Item.OBSIDIAN)
...: # top row
...: world.set_block(pos + Direction.EAST * x, + Direction.UP * 4, Item.OBSIDIAN)
...: for y in range(4):
...: # left side
...: world.set_block(pos + Direction.UP * y, Item.OBSIDIAN)
...: # right side
...: world.set_block(pos + Direction.UP * y + Direction.EAST * 3, Item.OBSIDIAN)
...:
ERROR: ValueError: <Item.OBSIDIAN: 'minecraft:obsidian'> is not in list
Does this all have to be typed into one line in order for it to work?
Will look at this tomorrow.
I can't immediately see how you got this error.
However from what you have pasted it looks like you are not doing the necessary indentation. In Python white space is significant and the code that is wrapped inside of a for statement needs to be indented to show it is 'inside' the loop. Four spaces of indentation is the usual convention.
I've pasted the code below as an example, note that each of the for loop statements are not indented but that the code they each loop around is indented.
Here is the tutorial's description which is a little inadequate. I'll improve the paragraph to highlight the importance of white space.
pos = world.player.pos
for x in range(4):
# bottom row
world.set_block(pos + Direction.EAST * x, Item.OBSIDIAN)
# top row
world.set_block(pos + Direction.EAST * x + Direction.UP * 4 , Item.OBSIDIAN)
for y in range(4):
# left side
world.set_block(pos + Direction.UP * y, Item.OBSIDIAN)
# top row
world.set_block(pos + Direction.UP * y + Direction.EAST * 3 , Item.OBSIDIAN)
c = get_client()
c.give("@a", Item.FLINT_AND_STEEL)
I've added a paragraph on indentation here https://gilesknap.github.io/mciwb/main/user/tutorials/04-loops.html#whitespace
@compX44 Let me know if adding indents to your typed code fixes the issue. Thanks.
It was the indentation. I've read your new paragraph and made sure that my code was indented in the appropriate places in the for loops and it worked. For some odd reason, I typed next to the dots. I probably went to do something there and forgot to correct myself before executing the code. I will try to be careful from now on. Thanks for your help.
I do have one more question for this part of your example:
for y in range(4):
# left side
world.set_block(pos + Direction.UP * y, Item.OBSIDIAN)
# top row
world.set_block(pos + Direction.UP * y + Direction.EAST * 3 , Item.OBSIDIAN)
For this section of your code, is it supposed to say # right side where it says # top row?
I made it say # right side for the sides of the nether portal when I executed my code, but I wanted to be sure that I wasn't misunderstanding anything.
@compX44 your change to the comment is correct. Thanks for reporting. I'll fix that!
@compX44 I really appreciate your effort in sticking with this.
When you get to Lists tutorial you will find that I have not completed it. I got that far and ran out of steam because there was very little interest in this project.
But now that I have interest I'll continue to write more tutorials. The library allows for quite interesting things in the Minecraft world and I have already made the code in src/demos for all of the tutorial titles I have in the documentation.
I've added some new tutorial titles to the index which I will write in the next few weeks.
You're welcome and thank you. I understand. Regardless, this is a fun endeavor.