on_player_message; how do I get to the message in Python AZNB?
When I run a display of the message parameter in this function, it says, "NPC: text" (when the NPC used a say command to say text)
How do I get access to the string with the contents of the message itself? I'd much rather check the text message than to check who sent the message and have to look for other stuff to figure out what message was sent, if possible. Is there such a thing as message.text or something? Please and thanks!
def on_player_message(message, sender, receiver, message_type):
-
Official comment
The message parameter is the correct way to get the contents of a chat message and it is the only property in python notebooks that has the text of a chat message. The [Username] at the beginning is a side effect of how Minecraft puts the output text back in chat, but the actual value of the message parameter passed into the function is the text the user typed. The message parameter is a python string, not an object, which means it doesn't have any message.text or message.value property or anything like that.
For example, in this code:def on_player_message(message, sender, receiver, message_type):
if(message == "jump"):
player.teleport(from_me(0,10,0))typing "jump" in chat will cause the code to run but changing the second line to if(message=="[username] jump") would not trigger the condition.
If you are specifically trying to get the Python code to work with NPC command buttons with /say, we do pre-pend [NPC] to the text, so you would just need to add that to your condition, for example:
if(message == "[NPC] jump"):
-
Thanks, @micah m
I can work with that. At least it's good to know I'm using the best data I can get ;)
Maybe I'll break the string after the space, or test with the full string, as you suggested.
Thanks, as always!0
Please sign in to leave a comment.
Comments
2 comments