GitHub-TC / EmpyrionScripting

Displays various informations directly and live on LCD screens and will support conveyor and construction control
GNU General Public License v3.0
34 stars 5 forks source link

Ability to dynamically call savegame scripts #28

Closed Shadowpheonix closed 1 year ago

Shadowpheonix commented 1 year ago

Is your feature request related to a problem? Please describe. Character limit on LCDs is too short for many scripts, and the current savegame scripts do not run often enough to be useful for some of these scripts.

Describe the solution you'd like I would like to see a new command such as {{RUN "<script_filename>"}} or similar that will execute the contents of a specified script file in the "Mods\EmpyrionScripting\Scripts" folder (or perhaps a "Mods\EmpyrionScripting\OnDemand" or similar folder instead). Even better if it allows passing variables/parameters either by treating any variables in the calling LCD as global, or by using something like {{RUN "<script_filename>" "<param1>" "<param2>"}}.

This would enable bypassing of the LCD character limit while still allowing use of per script priority and interval settings.

Describe alternatives you've considered Decreasing the SaveGameScriptsIntervallMS is a potential alternative, but that can have a significant impact on server performance.

Shadowpheonix commented 1 year ago

Just had a thought that calling and/or including code from other LCDs would work for this as well. IE: 2 LCDs, first named 'MoreScript:Test' (or whatever you prefer) containing some code such as...

{{#getitems @root.E.S @root.Data.TargetContainer}}
{{#each .}}
{{i18n ID}} has ID {{ID}}
{{/each}}
{{/getitems}}

Second LCD named 'Script:Test' with code similar to...

{{~set 'TargetContainer' 'MyStorage'}}
Here is a list of all items in {{@root.Data.TargetContainer}} with their item IDs...
{{#include 'MoreScript:Test'}}
GitHub-TC commented 1 year ago

Since SavegameScript cannot be deposited by players, this is not practical for players. But as a server operator, you can also write SaveGamescript in such a way that you query LCD with "configuration parameters" that the player can set up.

Shadowpheonix commented 1 year ago

Sorry, if I was not clear. My purpose for this was not to get user configuration info into a SaveGame script. Rather, it was a way to...

A) Get a SaveGame script to only run when explicitly called instead of repeating endlessly on the standard timer.

B) Allow modular code (code reuse/sub-routines/functions/whatever you want to call it) where you can re-use the same bit of code multiple times from within another script, without having to actually have the code typed in multiple times.

GitHub-TC commented 1 year ago

Take a look at this, Preston has created a "construction kit" of functions with this, you can do something like that too. https://github.com/Preston-Coding/EgsEsExtension

I'm trying to get Eleon to build a "computer block" without a display but with more memory and a simple text editor field.