Makecode Passing variables to "on chat command" block
I see there's a "+" symbol in the "on chat command" block that allows to pass a variable when calling the command from the chat window.
However, it seems that you can only pass a numeric variable. Is there any way to pass a string?
-
Good question. I tried to declare a string variable and use it to accept a string input to a chat command but was unsuccessful.
As an alternative, you could declare a function, perhaps:
0 -
Not allowing to pass string variables in chat commands seems a big limitation since the player can't invoke a function in the game, can he?
0 -
Can you help me understand the implementation you are going for here? What do you need to do with the string? Maybe we can find a work-around. =D
0 -
Could be something so simple as a chat command to greet another player in a multiplayer setting. The chat command would receive a string (a player's name) as a parameter and via a player.say block prints a greeting message personalized with the name received as a parameter
0 -
That's odd ... from the chat line you can only pass a numeric argument to a chat command. But when the player itself runs the chat command from inside the program, he can pass an argument ( player.runChatCommandWithArguments) ... but the argument has to be a string this time?
This is from the minecraft codebuilder help:
0 -
Hi,
I was wondering if this came to any conclusion - if it's now possible to pass arguments to chat commands as strings. As of today (Mar'25), I see that the blocks and javascript code still expects the arguments to be only numbers and I'm not able to change it (or at least I don't know how).
Debbie Alexander - on your question about what is the use-case. I'd like to do a very simple chat command to spawn a mob type based on the argument provided in the chat. While it would be possible to do it with something like "spawn 1", I'd prefer to be able to put "spawn zombie".
In the block code I would then check that argument if is equal to a string and spawn the proper mob object.
Thank you in advance for any info. Overall I have to admit it's strange I can't pass arguments as strings - this would be a more robust feature (if I needed a number, I would parse it, otherwise it's a string) .
-
Michal0
Please sign in to leave a comment.
Comments
6 comments