Skip to main content

Agent detect python

Comments

6 comments

  • Cathy Cheo-Isaacs

    Hi Francesca Germer! Which Python are you using, MakeCode or Notebooks?

    I had the same error in MakeCode, so I restarted with the same exact code that time, it worked.

    If you are coding Python in Notebooks, the commands and syntax are a little different. Hope this helps!

     
    0
  • Francesca Germer

    hmmm ok. I'm using notebooks. Is there a way to use inspect to detect just whether there's a block there or not? Not a specific block type, I just want to know if there's something there.

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Francesca Germer

    I believe that agent.detect("down") returns a true/false value for whether a block is present. =]

    0
  • Stefan Stoilov

    Hi. This might work. I have tried many ways to do this, but variables are the only way. code:

    i = 0
    detection = 0

    def on_forever():
        global i, detection
        i = GRASS
        detection = agent.inspect(AgentInspection.BLOCK, FORWARD)
        if i == detection:
            player.say("Grass Found")
    loops.forever(on_forever)
    0
  • Stefan Stoilov

    Change the grass to any valid block name.

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Hi, @Stefan Stoilov ! I'm thinking this is Minecraft Makecode Python? How did you found the AgentInspection.BLOCK information? I am always digging for more details, and I never know what I have missed! Please and thanks! Were you just able to use portions of the example code there?
    https://minecraft.makecode.com/reference/agent/inspect 

     

    I think Francesca is using Python Azure Notebooks.

    0

Please sign in to leave a comment.