We've split up the commands, scripting and mods, and add ons category! Please be sure you get your thread in the right place.

18

In-line functions in .mcfunction files

1 Comments

Please sign in to leave a comment.

Sorted by oldest
  • 4
    Registered User commented
    Comment actions Permalink

    I'll second this post because of the ability to have it all in one function. In the meantime we could have a check before each step of the inner function:

    execute as @e[type=cow] at @s run say Step 1
    execute as @e[type=cow] at @s run say Step 2

    But it is much more cumbersome to write and it messes up the collation of the steps, so that's why I agree with this post.

    I'm afraid I don't agree with the syntax for blocks though, braces {} seem too far deviated from Minecraft command syntax. Instead of that, I'd like to propose indentation blocks like in the language Python to show this. Indent should be one tab per indentation level. This renders as eight spaces here but many notepad editors allow customization:

    execute if <condition> run commands
    say Hello world!
    give @s minecraft:diamond 64
    execute as @e[type=minecraft:cow] at @s run commands
    data modify entity @s Motion[1] set value 5.0f
    particle minecraft:cloud ~ ~ ~ 0 0 0 0.1 10 normal

    The word commands can be anything, but it is required because I think you should be required to indicate when you are about to start an indented block, and a key word that activates it would best fit in with current command syntax.

    As for word choice, I thought of something that would make sense if you said it out loud (… if this condition is true, run the commands …) and I didn't want to use function because it was already taken. Feel free to suggest another word.