Recursive Function

Definition:
Recursive functions are functions that repeat or use their own conditions to trigger, sample:

Function (a)
If variable trigger_time != 10
Set variable increase (+=) trigger_time + 1
Game action wait = 1 tick
Call function (a)

What I just did basically there is a function with the name (a) and it has a triggering condition if the variable named “trigger_time” has a value < 10, it will increase the “trigger_time” variable’s value by 1 using the set variable +=. After the increment is finished it will wait for ~1 tick then call the function (a) again. The function will constantly trigger until the “trigger_time” variable’s value >= 10.

Adjust the speed:
Let’s denote the speed/the delays c/tick or second with c
is a variable. f is how many operations will be triggered per second.

Normally, the f value will be 1 - 20/second, if you try to put the value with decimal points (0.5, 0.004, etc…) within the wait action code then it will result in an error message instead. So to adjust the value of c you will then need to make a different recursive function:

Function (b)
If variable trigger_time_2 != 5
Set variable increase (+=) trigger_time_2 + 1
Call function (a)
Game action wait = 1 tick
Call function (b)

The function named “b” will consecutively calling the (a) function if the “trigger_time_2” variable has a value < 5. If a function gets triggered continuously then it would result in a phenomenon called “duping speed”. Basically “duping speed” is a phenomenon where the c value of a function got changed (because c is not a constant) using a method called duping function. Sounds pretty abstractive I know, let me elaborate on it for easier understanding:

We have a player event, the player event is called an “event” block that starts an “operation”. Operation means a chain of code. If we try to call a function within that operation while the function is already running then it will increase the c value and this is called a duping function.
Utilizing the “duping function” method we could potentially increase the c value in a considerable way. With each time the function gets triggered the speed of it will faster by 20 milliseconds:

c = f * 20 (operations per second)

There are some notes to this method:

  1. The c value can’t be smaller than 0.00166… milliseconds/operation or 800 operations/second because of java’s executable program limits. If it does then the game code will send an error message and the world will instantly be pushed back to /build mode.
  2. I recommend adding a condition block to check whether the loop is already executed before to avoid getting error messages.
  3. Mineland has a system that detects whether the function’s speed is faster than 400 operations/second or not. If yes then it gonna slow down the function without noticing to avoid lags.

Usages:
Recursive functions are used a lot in both external programming and in mineland coding. Like generating a platform row by row (this can be done simpler if mineland implemented parallel computation), foreach loop, extracting large values into smaller values, etc…

In general:
A recursive function is something that is very crucial in codes that require location manipulation, a multitude of entities, targets, etc… it is sometimes very short, only 3 - 4 blocks, sometimes very lengthy may be up to 3 - 4 operations but I think everyone should give this a try since it both uses in real programming and mineland coding and has a lot of practical usages and potentials.

4 Likes