Skip to content

CmdIndirect

Anthony Headley edited this page Mar 30, 2022 · 2 revisions

CmdIndirect(string:command, [object:undo[,object:target]]) : nil

Official Documentation

Brief

Enters a command on the command line with an optional undo object and target. Use this method of calling commands when the UI may be used. Using CmdIndirect() will cause the command to execute from the context of the Main Task and not the Lua Function. This function will run asynchronously so it will not wait for the call to complete before running following commands, this may cause commands the appear to show up out of order.

In many cases using Cmd will function function similarly however in some cases you many need to run a command from the context of the Main Task (or perhaps a specific user?). If you need the call to wait until complete and block Main Task (but not the Lua Task) until complete use the CmdIndirectWait

Passing an UndoObject will allow the console to roll back all changes applied with this object after it has been closed.

Target needs further information.

Parameters:

Name Description Optional
string:command A command line string
object:undo An Undo session Object
object:target ⚠️ Need further information

Returns:

nil ...

Example:

In this example I have patched 250,000 fixtures so the call to Thru at Full takes a little time.

local undo = CreateUndo()
Printf("Called BEFORE Level Adjustment")
CmdIndirect("Fixture 1 at 25", undo)
CmdIndirectWait("Thru at 50", undo)
CmdIndirect("Fixture 1 at 75", undo)
Cmd("Fixture 1 at 100", undo)
Printf("Called AFTER Level Adjustment")
CloseUndo(undo)

-- OK: Call Plugin 1
-- Called BEFORE Level Adjustment
-- OK:Fixture 1 At 25             
-- OK:Fixture Thru At 50
-- OK:Fixture 1 At 100         
-- Called AFTER Level Adjustment
-- OK:Fixture 1 At 75
Clone this wiki locally