Program Control
Call Scene auto_sync
Loads a scene as a function and calls it within the current task.
Calls a scene by passing its ID. The scene can be a timeline scene or a Lua scene.
- Function:
scenefrom the lua module - Parameters:
- scene_id: [str] Scene ID
- params: [list[any]] Input parameters. Optional, default empty
- dir: [str] Workspace name. Optional, default root directory
- Returns: [any] Scene return value
Example
Scene 10001:
local params = ...
print("params: ", params)
-- Set global variable
var_test = {
name = "Xiao Wu",
age = 16
}
return 4, 5, 6
Scene 10002:
print(scene(10001, {1, 2, 3})) -- Print scene return value
print(var_test) -- Print global variable
Start Task
Starts a new task, waits for the new task to start running, then returns the new task's task_id.
Serial tasks execute in queue, only one serial task can run at a time. Subsequent tasks will only run after the previous task completes, fails, or is terminated.
Parallel tasks execute immediately, multiple parallel tasks can run simultaneously, with independent environment variables.
Unlike scene, start_task creates a new thread to execute the task.
WARNING
- When the started scene contains motion related APIs, must start as serial task (
is_parallelisfalse) - In serial tasks, must start as parallel task (
is_parallelistrue), otherwise it will block
- Function:
start_taskfrom the lua module - Parameters:
- scene_id: [str] Scene ID
- params: [list[str]] Parameters, string array. Optional, default empty
- dir: [str] Workspace name. Optional, default root directory
- is_parallel: [bool] Whether to execute in parallel. Optional, default
false(serial) - loop_to: [int] Repeat execution count. Optional, default 1, 0 means infinite
- Returns: [int] Task ID (task_id)
Example
task_id = start_task("10024", nil, nil, false, 1) -- Serial execution task
Get All Task IDs
- Function:
get_task_listfrom the lua module - Parameters: none
- Returns: [list[int]] All incomplete task IDs
Example
print(get_task_list())
Get Serial Task ID 3.1.18
- Function:
get_main_task_idfrom the lua module - Parameters: none
- Returns: [int] Serial task ID. Returns
nilwhen no serial task exists
Example
task_id = get_main_task_id()
Get Current Task ID
- Function:
get_task_idfrom the lua module - Parameters: none
- Returns: [int] Current task ID
Example
print(get_task_id())
Wait for Task Completion
Note: Do not wait for yourself, waiting for yourself will never complete.
- Function:
wait_taskfrom the lua module - Parameters:
- task_id: [int] Task ID returned by
start_task. Optional, defaults to serial task
- task_id: [int] Task ID returned by
- Returns: [str] All
printoutput of the task
Example
stdout = wait_task(task_id)
print(stdout)
Get Task State
- Function:
get_task_statefrom the lua module - Parameters:
- task_id: [int] Task ID. Optional, defaults to serial task
- Returns: [str] Task state: "NONE" no task; "WAIT" queuing; "RUNNING" running; "PAUSE" paused; "SUCCESS" ran successfully; "INTERRUPTING" stopping; "INTERRUPT" stopped; "FAIL" ran failed
Example
state = get_task_state(task_id)
print(state)
Stop Task
Stops the specified task. When stopping a serial task, stop_move is automatically called to stop motion.
- Function:
cancel_taskfrom the lua module - Parameters:
- task_id: [int] Task ID. Optional, defaults to serial task
- Returns: [bool] Whether executed successfully
Example
cancel_task(get_task_id())
Pause Task
Pauses the specified task. When pausing a serial task, pause_move is automatically called to pause motion.
- Function:
pause_taskfrom the lua module - Parameters:
- task_id: [int] Task ID. Optional, defaults to serial task
- Returns: [bool] Whether executed successfully
Example
pause_task(get_task_id())
Compatibility Note
pause is an alias for this function.
Resume Task
Resumes the specified task. When resuming a serial task, resume_move is automatically called to resume motion.
- Function:
resume_taskfrom the lua module - Parameters:
- task_id: [int] Task ID. Optional, defaults to serial task
- Returns: [bool] Whether executed successfully
Example
resume_task(get_task_id())
Compatibility Note
resume is an alias for this function.
