Official Module Script

The folder to which the ParaSpace Scripts Folder field of the Para Script Loader component points is the official Module Script directory.

As shown in the preceding figure, under the ModuleScript directory, there is an index.lua file, which will be executed after the ParaSpace scene is loaded. The following shows a code segment in the index.lua file. You can reference other modules by adding relative paths to the file.

-- Load Global Module

list = require "Common.ParaList"

require "Common.ParaEvent"

Currently, the ParaSpace Scripts Folder contains 2 lua files—ParaList and ParaEvent. The ParaList.lua file implements a linked list. You can view the ParaList.lua file to learn how to use the list.

The ParaEvent.lua file implements event listening and distribution. The following example shows how to use the event component provided by ParaEvent:


local onClicked = event("evtName");

function Start()
    print("register onClicked event listener");
    local evtListener = onClicked:CreateListener(function()
        print("onClicked triggered");
    end);
    onClicked:AddListener(evtListener);
  
  	-- if don't want lisen then you can remove it
    -- onClicked:RemoveListener(evtListener);
end

function OnTestEvent()
    -- fire event
    onClicked();
end

You can add lua files to the official SDK directory or modify existing lua files as required. Note that you need to back up your changes because the files in the SDK directory may be replaced or modified during SDK upgrades.