[1.8.40] Draft.append & [1.9.23] Draft.merge

The Lua scripting language allows you to give your plugin more advanced features.

Moderator: Plugin Moderators

User avatar
ian`
Supporter
Reactions:
Posts: 117
Joined: 04 Apr 2020, 17:36
Location: Indonesien
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

[1.8.40] Draft.append & [1.9.23] Draft.merge

#1

Post by ian` »

Overview
Draft.append(Json) is a function to load Json code and Draft.merge(Json) is a function to merge Json object via Lua . Could be useful to generate JSON code dynamically and to define stuff generically.
:json + :lua: = :bb

How to use Draft.append
Technically, Draft.append only need one Json file as "main" part to include the script.

Code: Select all    Reset

[ { "id":"$draft_append_id", "type":"script", "script":"script.lua" } ]
JSON checker
Check

You have to write a string containing Json code and Draft.append inside the Lua script.

Code: Select all    Reset

local json1 = [[ [ { "id":"$example_script_type", "type":"script", "script":"function script:init() Debug.toast('Appending Json1 is working') end" } ] ]] local json2 = [[ [ { "id":"$example_other_type", "type":"animation", "frames":[{"bmp":"frame.png"}], "light": true, "light switching":true } ] ]] Draft.append(json1) Draft.append(json2)
Interactive Lua editor
Run
It only works in the "main" part of the script that will be called once when loading the script. The appended json code will be loaded right after the current loading json code was loaded.

How to use Draft.merge
You have to include the Lua script in each Json file. This function will merges the provided Json object into the json object is being loaded by the game. Will only have an effect for attributes that were not read by the game, yet.

Code: Select all    Reset

[ { "id":"$main_body_draft_merge", "type":"park", "frames":[{"bmp":"frames.png"}], "width":1, "height":1, "script":"script.lua" } ]
JSON checker
Check

for example, you want to add an animation object into that Json object. The Lua code will look like:

Code: Select all    Reset

local json = [[ { "animation":[{"id":"1x2l","x":7,"y":-6}] } ]] Draft.merge(json)
Interactive Lua editor
Run

Return to “Lua Scripting”