another blocker against mku equal 0 and added tprintf

This commit is contained in:
Olivier Gagnon 2021-08-27 11:05:36 -04:00
parent 3ab306f9d7
commit c9ab7908a7
6 changed files with 38 additions and 12 deletions

File diff suppressed because one or more lines are too long

20
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

@ -0,0 +1,17 @@
tprint() Netscript Function
===========================
.. js:function:: tprintf(format, args...)
:RAM cost: 0 GB
:param format: Format of the string to be printed.
:param args: Values to be formatted
Prints a raw formatted string to the terminal.
Example:
.. code-block:: javascript
tprintf("Hello world!"); // Prints "Hello world!" to the terminal.
tprintf("Hello %s", "world!"); // Prints "Hello world!" to the terminal.

@ -19,6 +19,7 @@ This includes information such as function signatures, what they do, and their r
sleep() <basicfunctions/sleep> sleep() <basicfunctions/sleep>
print() <basicfunctions/print> print() <basicfunctions/print>
tprint() <basicfunctions/tprint> tprint() <basicfunctions/tprint>
tprintf() <basicfunctions/tprint>
clearLog() <basicfunctions/clearLog> clearLog() <basicfunctions/clearLog>
disableLog() <basicfunctions/disableLog> disableLog() <basicfunctions/disableLog>
enableLog() <basicfunctions/enableLog> enableLog() <basicfunctions/enableLog>

@ -1112,8 +1112,13 @@ Industry.prototype.processProduct = function(marketCycles=1, product, corporatio
} else if (product.marketTa1) { } else if (product.marketTa1) {
sCost = product.pCost + markupLimit; sCost = product.pCost + markupLimit;
} else if (isString(product.sCost)) { } else if (isString(product.sCost)) {
if(product.mku === 0) {
console.error(`mku is zero, reverting to 1 to avoid Infinity`);
product.mku = 1;
}
sCost = product.sCost.replace(/MP/g, product.pCost + product.rat / product.mku); sCost = product.sCost.replace(/MP/g, product.pCost + product.rat / product.mku);
sCost = eval(sCost); sCost = eval(sCost);
} else { } else {
sCost = product.sCost; sCost = product.sCost;
} }

@ -936,6 +936,9 @@ function NetscriptFunctions(workerScript) {
} }
post(`${workerScript.scriptRef.filename}: ${argsToString(arguments)}`); post(`${workerScript.scriptRef.filename}: ${argsToString(arguments)}`);
}, },
tprintf: function(format, ...args) {
post(vsprintf(format, args));
},
clearLog: function() { clearLog: function() {
workerScript.scriptRef.clearLog(); workerScript.scriptRef.clearLog();
}, },