Agent detect python
I'm trying to get my agent to detect whether there's a block infront of him.
Code:
I keep getting the error message "Error:AttributeError: 'Agent' object has no attribute 'detect'.
I can't find ANY info on how to do this ANYWHERE! Plz halp!
-
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 -
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 -
I believe that agent.detect("down") returns a true/false value for whether a block is present. =]
0 -
Hi. This might work. I have tried many ways to do this, but variables are the only way. code:
i = 0detection = 0
def on_forever():global i, detectioni = GRASSdetection = agent.inspect(AgentInspection.BLOCK, FORWARD)if i == detection:player.say("Grass Found")loops.forever(on_forever)0 -
Change the grass to any valid block name.
0 -
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/inspectI think Francesca is using Python Azure Notebooks.
0
Please sign in to leave a comment.
Comments
6 comments