This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Commands API: tellraw command
Started by Pth1515, 16 February 2015 - 02:32 AMPosted 16 February 2015 - 03:32 AM
I need some help making a tell raw program, but I can't find any info on how to make one with the commands API any ideas? :)/>
Posted 16 February 2015 - 06:44 AM
Here's the documentation for the command.
So, going by that and taking the rest off the top of my head, to pass it through the API you'd do something like this:
@p specifies "the closest player to the block when the command runs", but you can stick specific names in there if you want, or use other filters.
So, going by that and taking the rest off the top of my head, to pass it through the API you'd do something like this:
commands.exec("tellraw @p {text:\"Hi there!\",bold:true}")
@p specifies "the closest player to the block when the command runs", but you can stick specific names in there if you want, or use other filters.
Posted 16 February 2015 - 03:33 PM
Since the commands are added dynamically, you can also just do this:
commands.tellraw("@p", "{text:\"Hi there!\", bold:true}")
No real difference, it just looks a little bit nicer.Posted 16 February 2015 - 03:56 PM
And, I believe:
This is pretty useful if you need to dynamically generate tell raw statements. This website is pretty useful for JSON generation for tellraw, I've used it a lot in the past.
command.tellraw("@p", {text = "Hi there!", bold = true})
This is pretty useful if you need to dynamically generate tell raw statements. This website is pretty useful for JSON generation for tellraw, I've used it a lot in the past.
Posted 16 February 2015 - 04:15 PM
Thanks for the help! :D/>
I'm going to go head and try it!
I'm going to go head and try it!
Posted 16 February 2015 - 04:32 PM
That's funny. I went to that website yesterday.And, I believe:command.tellraw("@p", {text = "Hi there!", bold = true})
This is pretty useful if you need to dynamically generate tell raw statements. This website is pretty useful for JSON generation for tellraw, I've used it a lot in the past.
One more thing: Does anyone know how to put a json in tArgs? Thanks in advance.
This is my code.
local tArgs = {...}
commands.tellraw(tArgs[1], tArgs[2])
Posted 16 February 2015 - 09:51 PM
Just pass it? JSON in CC is just a simple string:
> mytellrawpogram Pth1515 {text:"Hello!"}
Posted 16 February 2015 - 10:04 PM
Just pass it? JSON in CC is just a simple string:> mytellrawpogram Pth1515 {text:"Hello!"}
I just tried it like the above string and like this: [{text:\"Hi\"}]
Posted 16 February 2015 - 10:07 PM
Just pass it? JSON in CC is just a simple string:> mytellrawpogram Pth1515 {text:"Hello!"}
I just tried it like the above string and like this: [{text:\"Hi\"}]
And? BTW, you don't need those backslashes ( \ ) if you're passing it like an argument to the program. You only need them if you're writing that JSON code inside your program.
Posted 16 February 2015 - 10:19 PM
… and the quotes will not be passed on to tArgs. Putting them back would require analysis of each parameter to determine whether it's appropriate for them to be there.
Posted 16 February 2015 - 10:50 PM
Ok ill do something like this:… and the quotes will not be passed on to tArgs. Putting them back would require analysis of each parameter to determine whether it's appropriate for them to be there.
print("Player:")
player = read()
print()
print("JSON:")
json = read()
commands.tellraw(player, json)
Posted 17 February 2015 - 07:53 AM
… and the quotes will not be passed on to tArgs. Putting them back would require analysis of each parameter to determine whether it's appropriate for them to be there.
Right.. didn't thought shell parsed parameters like that. Although single quotes work perfectly:
> mytellrawpogram Pth1515 {text:'Hello!'}
But for ease of use I'd suggest instead of asking the user to input the actual JSON how about asking the user to only input the text he/she wants to send?
local args = {...}
local user = args[1] --# grab the username to which we will send the message
local message = args[2] --# grab the message
local bold = args[3] == "true" --# if there is a third parameter and it is equal to 'true' we'll make the message bold
local options = { --# setup the message
text = message,
bold = bold
}
commands.tellraw(user, options)
And the usage would be:
> tellraw <username> <message> [make bold text]
Example usage:
> tellraw Pth1515 "Hello there fellow ComputerCrafter!" true
Posted 17 February 2015 - 10:53 AM
What about all the other tags you could add to the text?
Seems to me that this is all just an attempt to recreate the - already included - "exec" script. Which itself is just a long-winded method of typing commands directly into MineCraft chat. An interesting exercise, to be sure, but not very practical.
Now, a full-blown text editor, on the other hand, something like this… Yeah, I know, not such a simple project, even when watered-down to ComputerCraft's interface. Still… possibilities!
Seems to me that this is all just an attempt to recreate the - already included - "exec" script. Which itself is just a long-winded method of typing commands directly into MineCraft chat. An interesting exercise, to be sure, but not very practical.
Now, a full-blown text editor, on the other hand, something like this… Yeah, I know, not such a simple project, even when watered-down to ComputerCraft's interface. Still… possibilities!
Posted 17 February 2015 - 12:37 PM
@Bomb Bloke I know that would be necessary but the point of this is so that a user could execute a completely custom JSON.… and the quotes will not be passed on to tArgs. Putting them back would require analysis of each parameter to determine whether it's appropriate for them to be there.
Right.. didn't thought shell parsed parameters like that. Although single quotes work perfectly:> mytellrawpogram Pth1515 {text:'Hello!'}
But for ease of use I'd suggest instead of asking the user to input the actual JSON how about asking the user to only input the text he/she wants to send?local args = {...} local user = args[1] --# grab the username to which we will send the message local message = args[2] --# grab the message local bold = args[3] == "true" --# if there is a third parameter and it is equal to 'true' we'll make the message bold local options = { --# setup the message text = message, bold = bold } commands.tellraw(user, options)
And the usage would be:> tellraw <username> <message> [make bold text]
Example usage:> tellraw Pth1515 "Hello there fellow ComputerCrafter!" true