Merge branch 'master' into 1.15

This commit is contained in:
gnembon committed 2020-01-05 17:12:03 -04:00
commit 9302a45510
2 files changed
+15 -8

No files matched your search

@@ -149,7 +149,7 @@ public class CarpetExpression
* <div style="padding-left: 20px; border-radius: 5px 45px; border:1px solid grey;">
* <p>
* <code>/script stop</code> allows to stop execution of any script currently running that calls the
* <code>gametick()</code> function which
* <code>game_tick()</code> function which
* allows the game loop to regain control of the game and process other commands. This will also make sure
* that all current and future programs will stop their execution. Execution of all programs will be
* prevented until <code>/script resume</code> command is called.
@@ -162,11 +162,11 @@ public class CarpetExpression
* exponentially with <code>n</code>. It takes a little over 50 milliseconds to do fib(24), so above one tick,
* but about a minute to do fib(40). Calling fib(40) will not only freeze the game, but also you woudn't be able to interrupt
* its execution. We can modify the script as follows</p>
* <pre>fib(n) -&gt; ( gametick(50); if(n&lt;3, 1, fib(n-1)+fib(n-2) ) ); fib(40)</pre>
* <pre>fib(n) -&gt; ( game_tick(50); if(n&lt;3, 1, fib(n-1)+fib(n-2) ) ); fib(40)</pre>
* <p>But this would never finish as such call would finish after <code>~ 2^40</code> ticks. To make our computations
* responsive, yet able to respond to user interactions, other commands, as well as interrupt execution,
* we could do the following:</p>
* <pre>fib(n) -&gt; ( if(n==23, gametick(50) ); if(n&lt;3, 1, fib(n-1)+fib(n-2) ) ); fib(40)</pre>
* <pre>fib(n) -&gt; ( if(n==23, game_tick(50) ); if(n&lt;3, 1, fib(n-1)+fib(n-2) ) ); fib(40)</pre>
* <p>This would slow down the computation of fib(40) from a minute to two, but allows the game to keep continue running
* and be responsive to commands, using about half of each tick to advance the computation.
* Obviously depending on the problem, and available hardware, certain things can take
@@ -2646,7 +2646,11 @@ public class CarpetExpression
* <h3><code>logger(expr)</code></h3>
* <p>Prints the message to system logs, and not to chat.</p>
* <h3><code>run(expr)</code></h3>
* <p>Runs a command from the string result of the <code>expr</code> expression, and returns its success count</p>
* <p>Runs a vanilla command from the string result of the <code>expr</code> and returns its success count</p>
* <pre>
* run('fill 1 1 1 10 10 10 air') -&gt; 123 // 123 block were filled, this operation was successful 123 times out of a possible 1000 blocks volume
* run('give @s stone 4') -&gt; 1 // this operation was successful once
* </pre>
* <h3><code>save()</code></h3>
* <p>Performs autosave, saves all chunks, player data, etc. Useful for programs where autosave is disabled
* due to performance reasons and saves the world only on demand.</p>
@@ -2666,8 +2670,8 @@ public class CarpetExpression
* accept expected tick length, in milliseconds. You can't use it to permanently change the game speed, but
* setting longer commands with custom tick speeds can be interrupted via <code>/script stop</code> command</p>
* <pre>
* loop(1000,tick()) // runs the game as fast as it can for 1000 ticks
* loop(1000,tick(100)) // runs the game twice as slow for 1000 ticks
* loop(1000,game_tick()) // runs the game as fast as it can for 1000 ticks
* loop(1000,game_tick(100)) // runs the game twice as slow for 1000 ticks
* </pre>
* <h3><code>current_dimension()</code></h3>
* <p>Returns current dimension that the script runs in.</p>
+5 -2
View File
@@ -809,6 +809,9 @@ public class Expression implements Cloneable
* </pre>
* <p>Ability to combine more statements into one expression, with functions, passing parameters, and global and outer
* scoping allow to organize even larger scripts</p>
* <h3><code>import(module_name)</code></h3>
* <p>Imports the entire content of another scarpet app by running the code in the current code context, making all
* functions and global variables available in the current script to use.</p>
* <h3><code>call(function, args.....)</code></h3>
* <p>calls a user defined function with specified arguments. It is equivalent to calling <code>function(args...)</code>
* directly except you can use it with function value, or name instead. This means you can pass functions to other user defined
@@ -1595,7 +1598,7 @@ public class Expression implements Cloneable
* <p>Evaluates expression <code>expr</code>, <code>num</code> number of times.
*<code>expr</code> receives <code>_</code> system variable indicating the iteration.</p>
* <pre>
* loop(5, tick()) =&gt; repeat tick 5 times
* loop(5, game_tick()) =&gt; repeat tick 5 times
* list = l(); loop(5, x = _; loop(5, list += l(x, _) ) ); list
* // double loop, produces: [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], ... , [4, 2], [4, 3], [4, 4]]
* </pre>
@@ -2735,7 +2738,7 @@ public class Expression implements Cloneable
*
* <h3><code>sleep(expr)</code></h3>
* <p>Halts the execution of the program (and the game itself) for <code>expr</code> milliseconds.
* All in all, its better to use <code>tick(expr)</code> to let the game do its job while the program waits</p>
* All in all, its better to use <code>game_tick(expr)</code> to let the game do its job while the program waits</p>
* <pre>sleep(50)</pre>
* <h3><code>time()</code></h3>
* <p>Returns the number of milliseconds since 'some point',