# ScriptGroup.Builder2

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder2

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/renderscript/ScriptGroup.Builder2 "View this page in Java")  

```
class Builder2
```

|---|----------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                         ||
| ↳ | [android.renderscript.ScriptGroup.Builder2](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#) |

*** ** * ** ***

| **This class was deprecated in API level 31.**
|
| Deprecated in Java.

The builder class for creating script groups

A script group is created using closures (see class[Closure](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Closure)). A closure is a function call to a kernel or invocable function. Each function argument or global variable accessed inside the function is bound to 1) a known value, 2) a script group input (see class[Input](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Input)), or 3) a future (see class[Future](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Future)). A future is the output of a closure, either the return value of the function or a global variable written by that function.

Closures are created using the[addKernel](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addKernel(android.renderscript.Script.KernelID,%20android.renderscript.Type,%20kotlin.Any))or[addInvoke](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addInvoke(android.renderscript.Script.InvokeID,%20kotlin.Any))methods. When a closure is created, futures from previously created closures can be used as its inputs. External script group inputs can be used as inputs to individual closures as well. An external script group input is created using the[addInput](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addInput())method. A script group is created by a call to the[create](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#create(kotlin.String,%20android.renderscript.ScriptGroup.Future))method, which accepts an array of futures as the outputs for the script group.

Closures in a script group can be evaluated in any order as long as the following conditions are met: 1) a closure must be evaluated before any other closures that take its futures as inputs; 2) all closures added before an invoke closure must be evaluated before it; and 3) all closures added after an invoke closure must be evaluated after it. As a special case, the order that the closures are added is a legal evaluation order. However, other evaluation orders are possible, including concurrently evaluating independent closures.

## Summary

|                                                                                                                                    Public constructors                                                                                                                                    ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder2](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#Builder2(android.renderscript.RenderScript))`(`rs:` `[RenderScript](https://developer.android.com/reference/kotlin/android/renderscript/RenderScript)!`)` Returns a Builder object |

|                                                                                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                                                                                 ||
|-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ScriptGroup.Input](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Input)!     | [addInput](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addInput())`()` Adds a script group input                                                                                                                                                                                                                                                                                                                                                                                                                |
| [ScriptGroup.Closure](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Closure)! | [addInvoke](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addInvoke(android.renderscript.Script.InvokeID,%20kotlin.Any))`(`invoke:` `[Script.InvokeID](https://developer.android.com/reference/kotlin/android/renderscript/Script.InvokeID)!`, `vararg` `argsAndBindings:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Adds a closure for an invocable function                                                                                                               |
| [ScriptGroup.Closure](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Closure)! | [addKernel](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#addKernel(android.renderscript.Script.KernelID,%20android.renderscript.Type,%20kotlin.Any))`(`k:` `[Script.KernelID](https://developer.android.com/reference/kotlin/android/renderscript/Script.KernelID)!`, `returnType:` `[Type](https://developer.android.com/reference/kotlin/android/renderscript/Type)!`, `vararg` `argsAndBindings:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!`)` Adds a closure for a kernel |
| [ScriptGroup](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup)!                 | [create](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Builder2#create(kotlin.String,%20android.renderscript.ScriptGroup.Future))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `vararg` `outputs:` `[ScriptGroup.Future](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Future)!`)` Creates a script group                                                                                                                               |

## Public constructors

### Builder2

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder2(rs: RenderScript!)
```

Returns a Builder object

|                                                            Parameters                                                            ||
|------|----------------------------------------------------------------------------------------------------------------------------|
| `rs` | [RenderScript](https://developer.android.com/reference/kotlin/android/renderscript/RenderScript)!:the RenderScript context |

## Public methods

### addInput

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addInput(): ScriptGroup.Input!
```

**Deprecated:** *Deprecated in Java.*

Adds a script group input

|                                                                                                          Return                                                                                                           ||
|-------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [ScriptGroup.Input](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Input)! | a script group input, which can be used as an argument or a value to a global variable for creating closures |

### addInvoke

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addInvoke(
    invoke: Script.InvokeID!, 
    vararg argsAndBindings: Any!
): ScriptGroup.Closure!
```

**Deprecated:** *Deprecated in Java.*

Adds a closure for an invocable function

|                                                                           Parameters                                                                            ||
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `invoke`          | [Script.InvokeID](https://developer.android.com/reference/kotlin/android/renderscript/Script.InvokeID)!:Invoke ID for the invocable function |
| `argsAndBindings` | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!:arguments followed by bindings for global variables              |

|                                                           Return                                                           ||
|-----------------------------------------------------------------------------------------------------------------|-----------|
| [ScriptGroup.Closure](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Closure)! | a closure |

### addKernel

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addKernel(
    k: Script.KernelID!, 
    returnType: Type!, 
    vararg argsAndBindings: Any!
): ScriptGroup.Closure!
```

**Deprecated:** *Deprecated in Java.*

Adds a closure for a kernel

|                                                                          Parameters                                                                          ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `k`               | [Script.KernelID](https://developer.android.com/reference/kotlin/android/renderscript/Script.KernelID)!:Kernel ID for the kernel function |
| `argsAndBindings` | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!:arguments followed by bindings for global variables           |

|                                                           Return                                                           ||
|-----------------------------------------------------------------------------------------------------------------|-----------|
| [ScriptGroup.Closure](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Closure)! | a closure |

### create

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun create(
    name: String!, 
    vararg outputs: ScriptGroup.Future!
): ScriptGroup!
```

**Deprecated:** *Deprecated in Java.*

Creates a script group

|                                                                                                                                                        Parameters                                                                                                                                                         ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name`    | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:name for the script group. Legal names can only contain letters, digits, '-', or '_'. The name can be no longer than 100 characters. Try to use unique names, to avoid name conflicts and reduce the cost of group creation. |
| `outputs` | [ScriptGroup.Future](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup.Future)!:futures intended as outputs of the script group                                                                                                                                                  |

|                                                     Return                                                      ||
|-------------------------------------------------------------------------------------------------|----------------|
| [ScriptGroup](https://developer.android.com/reference/kotlin/android/renderscript/ScriptGroup)! | a script group |