Skip to main content

Code not working

Comments

1 comment

  • Penny Support Team
    Beacon of Knowledge Expert (Gold) Support Team Member

    Hi Jason-

    Our engineers have been having a lively discussion about your question!

    The first issue is that pos() defines relative coordinates, so pos(200, 10, 200) is pretty far away from the player.  To indicate a position above the player, it would look more like pos(0, 10, 0).  This would put the anvil ten blocks above the player.

    The next issue is that in makecode, comparing positions with == doesn't work, since the type of a position can't be compared using ==.

    Here is some code that should work.  You need to convert the positions to strings, which can be compared with the == operator.  And then place your anvil.

    def on_forever():
        str1 = player.position().to_string()
        str2 = world(208, 75, 5).to_string()
        if (str1 == str2):
            blocks.place(ANVIL, world(208, 85, 5))
    loops.forever(on_forever)

     

    Here is another way to achieve this, using a function: 

    0

Please sign in to leave a comment.