WDL ScriptHook: Script Table

From Nomad DB
Revision as of 11:33, 15 April 2021 by Administrator (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Every Script has its own Script Table. It returns a Lua table that can be used for the following things:

  1. Storing variables for the Script
  2. Callback / Event Handlers
  3. Access script-specific functions

Using the Event Handlers is also the only way to properly unregister event listeners from the Game's event system. We strongly recommend not using global variables or functions in Scripts, since these won't be properly garbage collected and could cause conflicts with other Scripts.

For Mafia Definitive Edition, use ScriptHook.CurrentScript() instead.

Config Values

You can store persistent config values using the Script Table. Explained Here.

Script() in Action

This example illustrates how you can avoid using global variables & functions and how the Script() function can be used instead. Syntax:



local script = Script()
script.my_variable = 1234

function script:PrintMyVariable()



-- Prints 1234 twice

Event Handlers

Check out this guide about Event Handling.

Related Pages