3
Args in funcs
Hi! I need to pass arguments:
"/func fs:printii first second" My code:execute as @a run tellraw @s [{"text":"[","color":"gold"},{"text":" args[0]","color":"yellow"},{"text":"] ","color":"gold"},
{"text":" ","color":"white"}, {"text":"\"","color":"gold"},{"text":"args[1]","color":"yellow"},{"text":"\"", "color":"gold"}] it doesn't work
Create an account or sign in to comment.
3
If you need to pass specific values or arguments within a function I recommend exploring the lovely world of function macros.
I'm not terribly knowledgeable on them, but some rather good tutorials have been made to teach you the basics.
I'm not terribly knowledgeable on them, but some rather good tutorials have been made to teach you the basics.
Arguments cannot be directly passed to Minecraft functions, except for a single entity (via execute as ...).
However, there are ways to accomplish the same effect. One is to use scoreboard values as variables, and to set them before every function call, though for your use case this is likely impractical. The solution for string variables is to use the command storage, then use text components to read from the storage. Untested example:
To initialize the argument storage:
To call the function with inline arguments:
To use the arguments in a text component:
However, there are ways to accomplish the same effect. One is to use scoreboard values as variables, and to set them before every function call, though for your use case this is likely impractical. The solution for string variables is to use the command storage, then use text components to read from the storage. Untested example:
To initialize the argument storage:
data merge storage e:storage {args:["", ""]}
To call the function with inline arguments:
data modify storage e:storage args[0] set value "String 1"
data modify storage e:storage args[1] set value "String 2"
function e:print2
To use the arguments in a text component:
tellraw @a [{"text":"Argument 1: "}, {"nbt":"args[0]", "storage":"e:storage"}, {"text":"; Argument 2: "}, {"nbt":"args[1]", "storage":"e:storage"}]
yes they can in 1.20.2