Invoke Python-Function from Command-Block
Hi there,
I would like to invoke functions that are written in Code Builder (Python) in Minecraft. I can use listeners like player.on_chat or blocks.on_block_broken etc. but I would like to have some more flexible way of invoking Python-Functions.
Idealy I would like to just execute my functions via Command-Blocks. Is this possible? I tried different things (invoking directly, or writing something in Chat via a command-block that would trigger some on_chat listener, but neither worked).
Best regards
-
Sorry, i'm very late with my response, but this is exactly what I wanted. Thank you very, much!
1 -
Thank-you's are always welcome! Super job, Aleece Landis
0 -
Sorry for being late to the post, but I couldn't find better replies in my search attempts.
I tried to access the link: https://educommunity.minecraft.net/hc/en-us/community/posts/360072427991-MakeCode-and-Command-Blocks?input_string=Feature%20Request%20%3A%20Command%20blocks%20with%20makecode
However, it got routed to a page displaying errror message "
OOPS
You're not authorized to access this page"
Objective: Trying to get players (in survival mode) to execute the code that I've programmed via a button + command block.
0 -
Hi there,
I also no longer have access to the page. But it works as follows, if I remember correctly:
On the command block use /tell @p letsgo
(letsgo is just some random word you write in chat, then in python you can use on_tell_command)In Pyhton use
def on_tell_command():
blocks.place(ACACIA_FENCE,pos(4,3,0))
player.on_tell_command("letsgo", on_tell_command)Hope this helps.
0 -
Yes, totally works! I tested using the following code:
def give_diamond():
blocks.place(DIAMOND_BLOCK, pos(0, 2, 0))
player.on_tell_command("Diamond, please!", give_diamond)
def give_iron():
blocks.place(IRON_BLOCK, pos(0, 2, 0))
player.on_tell_command("Iron, please!", give_iron)1 thing I noticed is that switch to block coding and back to python changes the name of the functions to on_tell_command(), on_tell_command2() and so on. Kinda drives me nuts, but I like it because it discourages students from moving from python back to block coding.
0
Please sign in to leave a comment.
Comments
6 comments