[792] Real time script editing

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

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3414
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

[792] Real time script editing

#1

Post by Lobby » Tue Jan 07, 2020 18:28

Hi,

if you tried to use Lua for your plugins in the past you may have noticed that restarting the game every time you made a change to the script can be really time consuming. Wouldn't it be nice - and way more productive - to be able to edit a script with the game applying the changed automatically in real time? That's exactly what can be done by a newly introduced helper script called #LuaWrapper.

Right now your json to include a script may look like that:

Code: Select all

    "script":"myscript.lua"


For real time scripting use this form:

Code: Select all

    "script":"#LuaWrapper",        // Use the wrapper as primary script
    "meta":{
      "luawrapper":{
        "script":"myscript.lua",   // This is your script file
        "dev":true                 // Actually enable real time editing
      }
    }
This looks complicated, so how does it work? The #LuaWrapper script (that is predefined in the game) handles loading and reloading the given script file "myscript.lua" once it detects changes. The "dev":true is there as an easy switch to disable real time scripting, e.g. for release of the plugin.

Caveats
Of course there are some caveats because of which real time scripting is not used by default for scripts. Especially, it should not be used in published plugins:
  • Performance
    The game makes static assumptions about when a script has to be executed. For example, if a script doesn't implement the script:update function then it won't even be considered once the update event triggers. Scripts that may change at any point in time cannot be optimized in this regard as they have to be considered all the time. Another aspect is that the #LuaWrapper redirects calls on the real time script which adds some overhead.
  • Lua lifecycle
    The lifecycle for Lua scripts provides a well defined order of when script functions will be called. See the documentation about that. Real time scripts break this lifecycle by being loaded at a later point in time (usually after all other scripts have been initialized). Although the #LuaWrapper ensures that the init functions of the real time script will be called, dependencies to other scripts might not work as expected.
  • Hidden script object
    For normal scripts you can use Draft:getScripts() to access the script objects that are attached to a draft. However, since the real time script is wrapped by the #LuaWrapper you can only get access to that one. The real time script doesn't exist as an usual script object, instead it uses a table that uses the #LuaWrapper as a prototype. This is done so that from the point of view of the real time script, it is a full fledged script object.

See here for a video of how real time editing looks like:
http://www.youtube.com/watch?v=EE9qoKTCbZ0

The example can be downloaded from here:
realtimelua.zip
(6.86 KiB) Downloaded 8 times
...Have a nice stay

User avatar
Mg3094066
Inhabitant of a Supercluster
Reactions:
Posts: 3224
Joined: Sun May 28, 2017 1:50
Location: United Mexican States
Plugins: Show
Version: Beta
Phone model: LG H320mb 5.0.1

Plugin Creator

Platform

Re: [792] Real time script editing

#2

Post by Mg3094066 » Wed Jan 08, 2020 8:37

Not understanding rnything but ill say... its so great
I threw my dignity to trash and downloaded Free Fire... But someway i liked it ":'D

But i think it was too early to celebrate... my internet runs at 8kb...

Just wait another month... :bb

User avatar
Lobby
Developer
Reactions:
Posts: 3414
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Platform

Re: [792] Real time script editing

#3

Post by Lobby » Wed Jan 08, 2020 12:52

:lol:

Added a video for clarity.
...Have a nice stay

Post Reply Previous topicNext topic

Return to “Lua Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest