Constructor
new Thread(firstBlocknullable)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
firstBlock |
string |
<nullable> |
First block to execute in the thread. |
Members
(static, constant) STATUS_DONE
Thread status for a finished/done thread. Thread is in this state when there are no more blocks to execute.
(static, constant) STATUS_PROMISE_WAIT
Threads are in this state when a primitive is waiting on a promise; execution is paused until the promise changes thread status.
(static, constant) STATUS_RUNNING
Thread status for initialized or running thread. This is the default state for a thread - execution should run normally, stepping from block to block.
(static, constant) STATUS_YIELD
Thread status for yield.
(static, constant) STATUS_YIELD_TICK
Thread status for a single-tick yield. This will be cleared when the thread is resumed.
blockContainer :Blocks
The Blocks this thread will execute.
Type:
(nullable) blockGlowInFrame :string
Which block ID should glow during this frame, if any.
Type:
- string
isKilled :boolean
Whether the thread is killed in the middle of execution.
Type:
- boolean
requestScriptGlowInFrame :boolean
Whether the thread requests its script to glow during this frame.
Type:
- boolean
stack :Array.<string>
Stack for the thread. When the sequencer enters a control structure, the block is pushed onto the stack so we know where to exit.
Type:
- Array.<string>
stackFrames :Array.<_StackFrame>
Stack frames for the thread. Store metadata for the executing blocks.
Type:
- Array.<_StackFrame>
status :number
Status of the thread, one of three states (below)
Type:
- number
(nullable) target :Target
Target of this thread.
Type:
(non-null) topBlock :string
ID of top block of the thread
Type:
- string
(nullable) warpTimer :Timer
A timer for when the thread enters warp mode. Substitutes the sequencer's count toward WORK_TIME on a per-thread basis.
Type:
Methods
atStackTop() → {boolean}
Whether the current execution of a thread is at the top of the stack.
Returns:
True if execution is at top of the stack.
- Type
- boolean
getParam(paramNamenon-null) → {*}
Get a parameter at the lowest possible level of the stack.
Parameters:
Name | Type | Description |
---|---|---|
paramName |
string | Name of parameter. |
Returns:
value Value for parameter.
- Type
- *
goToNextBlock()
Switch the thread to the next block at the current level of the stack. For example, this is used in a standard sequence of blocks, where execution proceeds from one block to the next.
initParams()
Initialize procedure parameters on this stack frame.
isRecursiveCall(procedureCodenon-null) → {boolean}
Attempt to determine whether a procedure call is recursive, by examining the stack.
Parameters:
Name | Type | Description |
---|---|---|
procedureCode |
string | Procedure code of procedure being called. |
Returns:
True if the call appears recursive.
- Type
- boolean
peekParentStackFrame() → (nullable) {object}
Get stack frame above the current top.
Returns:
Second to last stack frame stored on this thread.
- Type
- object
peekStack() → (nullable) {string}
Get top stack item.
Returns:
Block ID on top of stack.
- Type
- string
peekStackFrame() → (nullable) {object}
Get top stack frame.
Returns:
Last stack frame stored on this thread.
- Type
- object
popStack() → {string}
Pop last block on the stack and its stack frame.
Returns:
Block ID popped from the stack.
- Type
- string
pushParam(paramNamenon-null, value)
Add a parameter to the stack frame. Use when calling a procedure with parameter values.
Parameters:
Name | Type | Description |
---|---|---|
paramName |
string | Name of parameter. |
value |
* | Value to set for parameter. |
pushReportedValue(value)
Push a reported value to the parent of the current stack frame.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | Reported value to push. |
pushStack(blockId)
Push stack and update stack frames appropriately.
Parameters:
Name | Type | Description |
---|---|---|
blockId |
string | Block ID to push to stack. |
reuseStackForNextBlock(blockId)
Reset the stack frame for use by the next block. (avoids popping and re-pushing a new stack frame - keeps the warpmode the same
Parameters:
Name | Type | Description |
---|---|---|
blockId |
string | Block ID to push to stack. |
stopThisScript()
Pop back down the stack frame until we hit a procedure call or the stack frame is emptied