Actions

Difference between revisions of "Optimizing command block systems using functions"

From Zedwiki

(Created page with "'''This tutorial covers ways to use functions to make command block systems more efficent in cpu usage''' Every single command block running in the world will create load, and...")
 
m (Added category)
Line 16: Line 16:
  
 
More to follow...
 
More to follow...
 +
 +
[[category:tutorial]]

Revision as of 11:17, 3 October 2018

This tutorial covers ways to use functions to make command block systems more efficent in cpu usage Every single command block running in the world will create load, and with many commands running at once can cause constant lag and excessive cpu usage. While most command block minigames will run fine without these methods, very complex ones may need them to run well.

Causes of command block load

Command block chains need to figure out which command block should be executed next, so that the chain happens in the right order. Functions don't need to do this and so have an immediate benifit even if the commands are the same. Entity selectors have to check the list of entities on the server to find the ones that match. More entities to check increases this (already significant) load. Using the @s selector means a list of one entity (the executer) is checked rather than a long one of other entities. Location checks in selectors also give notable load, with large ones being worse. Every command run will have some load, regardless of what it is. This gives us some goals to aim for when optimizing command block systems.

  • Use functions rather than command block chains
  • Reduce the number of selectors, replacing with @s where possible
  • Reduce number of commands running every tick
  • Reduce number of location checks in selectors

Functions

A function is a plain text file with commands in it, one per line, that are executed top to bottom. It has the file extension .mcfunction and needs to use UTF-8 encoding. Notepad++ is a free editor that can do this. For the dungeon dash abilities, the functions are placed in data/functions/dungeondash/abilities. dungeondash is the namespace, abilities is the sub folder containing the function files themselves.

The Tutorial

In order to lower the cpu usage of our commands we will primarily use functions and the @s selector.

More to follow...