Skip to main content

StartVirtualScript

This function was added in DSL 1

Description

Creating a virtual script is very similar to creating a script with StartScript, except that a function is given instead of a file.

This allows you to get the benefits of having another script object, without the need for a dedicated file.

If you do not care about giving it a special name, you can just give the func as the first argument.

function StartVirtualScript(name, func) --[[ ... ]] end

Parameters

  • name: string - The name of the script to start. This is optional, and if not provided, the function will be used as the name.
  • func: function - The function to run as the script. This function should not take any parameters and should return nothing.

Return Values

  • script: userdata|script|nil - The script object that was started. This will be nil if the script was terminated before this function returned. userdata if checked with type(script), script if checked with type2(script).

Versions

  • DSL4 - The optional name argument was added.

Example

StartVirtualScript('MyVirtualScript', function()
print('Hello from a virtual script!')
end)

See Also