From 17e30f062d9f1374dd80895616c5d3513ce8234e Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Tue, 23 Jan 2024 20:10:06 +0100 Subject: [PATCH] Document global operators --- .../assets/integratedscripting/lang/en_us.json | 10 ++++++---- .../data/integratedscripting/info/scripting_info.xml | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/integratedscripting/lang/en_us.json b/src/main/resources/assets/integratedscripting/lang/en_us.json index 8fb7f6d2..c8555545 100644 --- a/src/main/resources/assets/integratedscripting/lang/en_us.json +++ b/src/main/resources/assets/integratedscripting/lang/en_us.json @@ -120,11 +120,13 @@ "info_book.integratedscripting.writing.functions.text5": "For example, you can create a function with a single &8Item&0 argument that returns a &9Boolean&0 to use as filter &2Operator&0 for filtering a list of items that you read from a Chest.", "info_book.integratedscripting.writing.functions.text6": "Below, you can find examples of different types of functions that could be created.", - "info_book.integratedscripting.writing.globals": "Global values", - "info_book.integratedscripting.writing.globals.text1": "TODO", - "info_book.integratedscripting.writing.globals.text2": "TODO", + "info_book.integratedscripting.writing.globals": "Global operators", + "info_book.integratedscripting.writing.globals.text1": "When writing JavaScript code, you can make use of the global &oidContext&r variable to access all Integrated Dynamics operators as functions through the &oops&r field. This allows you to make use of built-in operators when creating new ones.", + "info_book.integratedscripting.writing.globals.text2": "For example, you can write an &8Item&0 filter that checks if an item is stackable and if it has a stack size of at least 16, as shown below.", + "info_book.integratedscripting.writing.globals.text3": "To know what the name is of the operator you want to execute, you can look at their global name via the operator tooltips inside the &lLogic Programmer&r or in the list of operators in the Logic Programming section of this book.", + "info_book.integratedscripting.writing.globals.text4": "Since invoking operators via &oidContext&r can become quite verbose, you can choose to store operators in a custom constant variable, as shown in the second example. Alternatively, you can make use of &oobject methods&r, which are discussed in the next section.", - "info_book.integratedscripting.writing.methods": "Object value methods", + "info_book.integratedscripting.writing.methods": "Object methods", "info_book.integratedscripting.writing.methods.text1": "TODO", "info_book.integratedscripting.writing.methods.text2": "TODO" } \ No newline at end of file diff --git a/src/main/resources/data/integratedscripting/info/scripting_info.xml b/src/main/resources/data/integratedscripting/info/scripting_info.xml index a3a0fe00..b3ccda52 100644 --- a/src/main/resources/data/integratedscripting/info/scripting_info.xml +++ b/src/main/resources/data/integratedscripting/info/scripting_info.xml @@ -107,6 +107,17 @@ const isOdd = (value) => value % 2 !== 0;
info_book.integratedscripting.writing.globals.text1 info_book.integratedscripting.writing.globals.text2 + info_book.integratedscripting.writing.globals.text3 + info_book.integratedscripting.writing.globals.text4 + function filterItem(item) { + return idContext.ops.itemstackStackable(item) && idContext.ops.itemstackStacksize(item) >= 16; +} + +const stackable = idContext.ops.itemstackStackable; +const stacksize = idContext.ops.itemstackStacksize; +function filterItemCompact(item) { + return stackable(item) && stacksize(item) >= 16; +}