3

Args in funcs

User4804652G's Avatar User4804652G10/5/23 12:37 pm
3 emeralds 138 3
11/12/2023 3:23 am
Peril108's Avatar Peril108
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
Posted by User4804652G's Avatar
User4804652G
Level 1 : New Miner
1

Create an account or sign in to comment.

3

Gamingbarn
10/15/2023 12:09 pm
Level 70 : Legendary Programmer
Gamingbarn's Avatar
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.
1
-ghost-
10/05/2023 1:23 pm
Level 23 : Expert Ranger
-ghost-'s Avatar
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:
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"}]
1
Peril108
11/12/2023 3:23 am
Level 1 : New Crafter
Peril108's Avatar
yes they can in 1.20.2
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome