This generator allows you to easily create complex command block mechanics using a programming-like syntax, making many different types of logic, effects, and control flow easier to create!
A good first step towards understanding how to use this tool effectively would be to check out the list of example projects below! Each one is filled with comments, helping you understand why each line is important.
There are 2 different types of variables that you can define and use in your code. The type of variable that you use will affect they way that they are compiled and react to changes!
The first type of variable is a hard-coded variable. This type of variable cannot be changed during "run-time" (in-game). These are mostly useful for values that are used often throughout your code, but that you may need to change periodically. Hard-coded variables can hold any value, such as a string or number. If a hard-coded variable is set equal to a command, then it will hold the coordinates of the command block that is generated for the command.
The second type of variable is a dynamic variable. This type of variable can be changed during "run-time" (in-game). This type of variable holds integer values, and can be used in math operations.
Dynamic variables can be used in if-statements, function calls, and built-in functions as well.
A function allows you to reuse a block of code as many times as you need. A function can be declared with arguments to allow information to be passed and used inside it when it is called.
To declare a function that takes arguments when called, list them inside the parentheses separated by commas.
The instant keyword makes a function call run exactly on the line it is called from in-game, instead of running at the end of the current tick. Though this may be necessary for certain things, it is recommended to not use this when it is not needed, as it will cause slightly more lag than a non-instant call if you have called it many times in your code. In addition to making function calls run instantly, you can make a conditional repeating block of code run instantly with the instant keyword. If it were not instant, then the code would run a tick after the condition is found to be true (same with the "else" block if there is one).
Built-in functions allow you to do certain tasks and calculations easily, such as sine, cosine, random number generators, doing something where the player is looking, and moving one entity towards or away from another.
These trignomic functions allow you to easily implement useful sine/cosine waves in your code. The angle you pass to these must be in degrees.
Tip: If you must use multiple sines and/or cosines in the same line of code, pass the same variable as the argument into all of them to minimize the amount of lag in-game! Each new variable that is passed on a new line forces the amount of generated code to increase exponentially.
The random built-in function returns a random integer each time it is called. This integer will always be between the min and max values that you pass to it.
You can use this value in scoreboard commands to make it useful in mechanics.
Do you need to spawn an entity, create a particle effect, or do anything else at the location a player or entity is looking at? Use the facingDirection or facingPoint built-in functions! facingDirection only checks the player or entity's horizontal rotation, while facingPoint takes the vertical rotation into account as well.
The arguments for facingDirection and facingPoint are in the order as follows:
distance, x-offset, y-offset, z-offset, degreeOffset, overrideAccuracy
You can move one player or entity towards another by using the moveToward built-in function. The arguments for this function are in the order as follows (? = optional):
movingEntity, targetEntity, ?speed, ?walkUpBlocks, ?minDistance, ?useTp, ?flySpeed, ?overrideAccuracy
The rotation accuracy of these can be set in your options, by changing the Sine/Cosine accuracy. Decrease the accuracy to reduce the number of generated command blocks, making it less laggy but also making the movingEntity's movement more jagged.
The opposite of the moveToward function is moveAway. The arguments for it are as follows:
movingEntity, awayFromEntity, ?speed, ?walkUpBlocks, ?maxDistance, ?useTp, ?flySpeed, ?overrideAccuracy
If statements run one block of code if the condition is found to be true, and another one if it is not.
To run a block of code when the if statement's condition is found to be false, use the else keyword.
To make a certain chunk of code repeat until stopped with the stop keyword, you can create a repeating section of code.
The word main in the code snippet above can be changed to any word that you want to use as the name of the repeating section. This name must be unique from any other repeating section since it will be used when you want to start or stop the repeating section.
The delay keyword makes a chunk of code run after a certain number of ticks. (1 tick = 1/20th of a second)
Any code after the closing bracket of the delay block will not be delayed; it will run normally.