StartScript
This function was added in DSL 1
Description
Start a DSL script and add it to the current collection.
info
This differs from LoadScript
as starting a script means it gets its own script object, environment, and flow threads.
name
is given as a relative path.
You can optionally supply your own environment
instead of letting the default one be generated.
The script
may not be returned if the script is terminated before this function returns.
function StartScript(name, environment) --[[ ... ]] end
Parameters
name
:string
- The name of the script to start.environment
:table
- Optional. The environment to use for the script. If not provided, a new environment will be created.
Return Values
script
:userdata|script|nil
- The script object that was started. This will benil
if the script was terminated before this function returned.userdata
if checked withtype(script)
,script
if checked withtype2(script)
.
Versions
- DSL4 - Passing a custom
environment
no longer stops a script from creating normal script flow threads.
Example
Run two scripts in the same collection by using StartScript
.
main.lua
StartScript("secondary.lua")
function main()
while not SystemIsReady() do
Wait(0)
end
while true do
TextPrintString("hello from main.lua", 0, 1)
Wait(0)
end
end
secondary.lua
function main()
while not SystemIsReady() do
Wait(0)
end
while true do
TextPrintString("hello from secondary.lua", 0, 2)
Wait(0)
end
end
See Also
- DSL