Skip to main content

Python Notebooks - MegaJump

Comments

4 comments

  • Official comment
    Micah M
    Beacon of Knowledge

    Hi Debbie Alexander,

    The tutorial is doing a little magic in the background to identify when the user types jump and call the chat_say_jump( ) function.
    If you want to write equivalent code on your own, you will need to check what chat message the player typed. This function will receive chat from players and pass it as the message variable. It will fire every time chat is received.

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

    You can then take message, convert it to a number and pass it to your jump function. Note that for my code to work the chat message needs to be an int (whole number), but you could add extra code to make sure the message is a number.

    def on_player_message(message, sender, receiver, message_type):
       chat_jump_high(int(message))
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Micah-M I have been working hard on these (razzum frazzum) events, and this one is a pill!

    It works fine in the Notebooks tutorial page, but when you copy over the exact code to a fresh Notebooks page outside of the tut, it doesn't recognize the event. I have edited this thing six ways to Sunday. With parameter, without, renamed, hard-coded coords, I'm at the end on this one! It is just a chat command with a parameter, I suppose, but I cannot make it go!

    (I can get a plain chat event to work like this, but not with a parameter)

    def pickle():
        say("you said jump")
        player.teleport(from_me(0,100,0))
    on_chat_event("jump",pickle)
     
    ***************
    the original code from the tutorial is:
    def chat_say_jump(height):
        say("You said jump!")
        user.teleport(from_me(0, height, 0))
    and doesn't work either...
    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Okay I tried it like this, and I didn't even need to say anythin in chat... It just ran automatically, which I do not understand at all...whatsoever... Micah-M

    def pickle(high):
        say("you said pickle")
        player.teleport(from_me(0,20,0))
    high = 0
    on_chat_event("pickle",pickle(high))
    0
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star

    Micah-M  Thanks ever so much for the assist. I am doing something wrong, though. When I run the function, I cannot get the message parameter to be happy. Even just a say command throws an error. It still executes, but this is what I see:

    0

Please sign in to leave a comment.