Skip to main content

def player_chat(message):

Comments

17 comments

  • Dominick Support
    Bug Zapper Support

    Thank you for providing that information. I would first check that you have creative mode enabled with the /c command and try that. 

    0
  • Jenny Goding

    This one has been a known issue since at least the start of last year, but it just gets ignored when people raise it here.  Or irrelevant suggestions are made that don't address the problem.

    Yes, it only seems to work in the 'Agent Moves' tutorial, not in a new project.

    My work-around has been to define a function instead, eg. 

    def agentmove():

        agent.move("forward")

    Then call the function:

    on_chat_event("test1", agentmove)

    Where "test1" is the chat command

    Some of my students have had issues getting this to work in 1.18.32, so see how this goes.

     

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Well, I have spent awhile looking over events in the new Python Azure Notebooks interface this morning. At first, from looking at the Reference guide, I thought there weren't any chat events at all! I couldn't find anything. Laylah Bulman

    So I tried running the code from my blog, which is the easiest example I know. Low and behold, the code doesn't run, because not only are the location parameters changed, but the order of these parameters are changed as well. Jenny Goding you may have to check and switch the order of some parameters for event functions.  http://tech.grandmadeb.com/index.php/2021/05/15/event-handlers-in-python-notebooks-with-minecraft-education-edition/

    So I tried to re-create your code, Bo van der Steen I was able to use the Reference guide - but the code only worked for one iteration successfully, and then it had an error. Me, my device, or the Python, idk. But I am pretty sure this is the right track. The agent was able to move the first time.

    0
  • Jenny Goding

    Debbie Alexander you are a legend! - switching the parameters around for on_chat_event solved the problem, and it now works perfectly in 1.18.32, as follows:

    def agentmove():

        agent.move("forward")

    on_chat_event(agentmove, "test1")

    So, the order for the parameters is now on_chat_event(<function to call>, <chat command>)

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    =] Glad to help. I wish I could wave a wand and switch all my screenshots, powerpoint explanations and text docs with exemplars... lol

    Maybe we can collaborate sometime. We are trying to get a coding together time for Python users figured out. Interested? DM me on Twitter! I want to get a list of folks going. 

    0
  • Jenny Goding

    I like the sound of that!  I tried to DM you on Twitter, but your account is not currently set up to be messaged - nevertheless, you can count me in!

    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    @Penny would you be able to send Jenny my email address, since she was unable to contact me on Twitter, please?

    0
  • Josh Kitzerow

    I know this is an older post but I wanted to throw in my "2 cents".

    I was experiencing the same issue where the text chat command ONLY worked inside the "Agent Moves" and I managed to figure it out (I apologize if someone already figured it out).  You need the following function(s) in order to get it to work (obviously change the player_chat function to suit your needs):

    def player_chat(message):
         if message == "tp":
              agent.teleport()
         elif message == "fd":
              agent.move("forward")
         elif message == "rt":
              agent.turn("right")
     
    def on_player_message(message, sender, receiver, message_type):
         player_chat(message)
     
     
    0
  • Moderator Beacon of Knowledge Super Star

    Hey, Josh, pleased to meet you, and thanks for chiming in!

    I'm always happy to meet another Python AZNB coder! Hope you can join us in a group meet up this summer! 

    So you've discovered a hint for us? i love it! If I'm understanding you, in order to coordinate between the chat commands and the Python Event handler commands, we need to run both of these functions, and then I can add commands in chat to execute Python commands in my game? Are we dealing with limits on data type for message? IOW we have had trouble in the past with only integers being passed in MakeCode. This is great! Can't wait to test!

    # my own code which runs based on text chat input
    def my_custom_event(message):
    # all chat is tested
    if message == "Howdy":
    say("Pleased to meetcha!")
    def on_player_message(message,par2,par2,par4):
    my_custom_event_name(message)


    0
  • Josh Kitzerow

    I honestly just found this out yesterday and wanted to post it because I knew you would run with it immediately.

    Here is my FULL code I was using chat commands.  MY assignment was for students to change the materials while they were building with their agents so I was trying to see if I could change it with chat commands and everything works perfectly.

    import random, time

    blocks = ["Stone","Granite","Polished Granite","Diorite","Polished Diorite"]

    def material():
       material = random.choice(blocks)
       agent.give(material,64,1)
       #time.sleep(.1)
       say(material)

    def wall():
       height = agent.position.y
       say(height)

       for h in range(5):
           if (agent.position.y == (height + 1) or agent.position.y == (height + 2)):
               agent.give("Yellow Stained Glass",64,1)
           else:
               agent.give("Black Terracotta",64,1)
           agent.move("up")
           for i in range(4):
               for j in range(10):
                   agent.move("forward")
                   agent.place("down", 1)
               agent.turn("right")
              
    def player_chat(message):
       if message == "tp":
           agent.teleport()
       elif message == "fd":
           agent.move("forward")
       elif message == "mats":
           material()
       elif message == "wall":
           wall()

    def on_player_message(message, sender, receiver, message_type):
       player_chat(message)

    I found this out by running the "Agent Moves" tutorial in a web browser and inspecting the activity in the web browser console.  I have not had time to 'break' it yet since I am also currently teaching it in classes (Programming Teaching in High School).

    Let me know what you find out.  When I get some air to breath, I will start writing my own tutorials because some of the tutorials are not working like I would hope they would.

    .....Now about this group meet up.  When is it? My calendar is pretty packed writing curriculum this summer and travel softball, and college freshman (teenage daughters), but I would love to hop on a Zoom or Google Meet if possible just to see everyone's vision on this stuff.  I was leaning towards getting rid of Minecraft Education for my classes because the tutorials are kind of broken with this new update, but I can be convinced to change my mind since the district invested so much time and resources to get it working

     

     

    0
  • Moderator Beacon of Knowledge Super Star

    I love the random use of the array, and the selection based on the coordinate data. 

    We taught a CS class with almost all of the Texas CS1 standards covered in Python AZNB this year. I think it's doable. =] I love it because, having taught C++, Python in another IDE, JavaScript (briefly) and a few random things here and there., teaching Python AZNB in MC:EE has students running to get to my class, looking for more ways to work, and engaged on every assignment. I love it!

    0
  • Josh Kitzerow thanks for raising this. As this tutorial is designed for beginners coming from Makecode, we wanted to be able to replicate the on_chat event ease of use that is enjoyed by Makecode. Unfortunately the Python library in below is rather more complex for chat triggers, as you have noticed, so we decided to create a simplified version just for this tutorial (and mega jump) as a majority of students are unlikely to use this outside of the tutorials.

    We are going to see about adding a prompt at the end of the task, just to highlight that the full on_player_message command (with it's 4 parameters) is available elsewhere and more details on using it, can be found in the reference guide.

     

    You mention issues with other tutorials? Are you able to describe in more detail what these might be, as we are happy to investigate any issues, as long as we know that there are issues!

    1
  • Josh Kitzerow

    The other issues my students and I are experiencing pertain to the Python Islands.  Honestly, I didn't even want to go past the 2nd island because it was unplayable.  This might pertain to the 1.19 update, but here you go:

    Python Island 01

    1. Navigation to subsequent NPCs is very inconsistent.  Students will sometime be told to go to the farmhand when they haven't acquired their agent license and they could not advance.  The only solution was to restart the lesson from the beginning
    2. Getting stuck "literally" and not able to move anywhere (restart of lesson necessary).
    3. Crashing on Chromebooks

    Python Island 02

    1. In the forest with the fog, the agent would not advance to the next location.  I even tried to manually run the functions using commands to see if I could advance through but could not get passed that point (I was on a Macbook Pro)

    I honestly think there is a lack of testing with the tutorials (no offense to anyone because I know it takes a lot of time for little if any reward), but students try to 'break' things before they want to actually complete them so we need to make sure they are unbreakable.

    I have other issues but they pertain to MakeCode blocks so I will leave it out of this thread.

    0
  • Laylah Bulman

    Josh Kitzerow Fot the Python Islands, are these experiences in CHrmoeboks and Mac?

    0
  • Josh Kitzerow

    Both

    Island 01 - Primarily Chromebooks but I experienced some on my Macbook

    Island 02 - Only on Macbook but that was because I never assigned it to my students because I could not get passed the Fog Forest part

    0
  • Josh Kitzerow unfortunately with Minecraft, content just breaks over time with new updates now and then, in some cases in rather unexpected ways...

    Turns out the issue mentioned with Python Island 2 was very much one of those, an unexpected very minor behaviour change in the game (that likely came from Minecraft Bedrock directly, nothing to do with the education team), broke a behaviour in the game. Certainly not something expected from the official changelogs.

    Please do continue to report any issues like these you come across to the support team, as they do generally make their way back to us (the developers and maintainers of the Python Islands series of worlds), so we can look at resolving them ASAP. And don't worry, there is plenty of testing done on content like Python Islands in the library, but there is always going to be a limit in what we can do. Students will always try to find ways around what we create, especially with new ways added every new version of Minecraft!

    The issues for example you mentioned with Python Island 1, any screen recordings, screenshots etc showing these issues in more detail so we can track them down would be super helpful, as these aren't issues we can reproduce? (these are probably best put through as a support ticket)

    0
  • Also just to add Josh Kitzerow, the forest (fog) issue has been resolved and a new version of Python Island 2 has been submitted for uploading (hopefully in the coming days) to the world library.

    1

Please sign in to leave a comment.