2022-10-21 17:16:00 +02:00
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home ](./index.md ) > [bitburner ](./bitburner.md ) > [NS ](./bitburner.ns.md ) > [spawn ](./bitburner.ns.spawn.md )
## NS.spawn() method
2023-09-27 07:31:47 +02:00
Terminate current script and start another in a defined number of milliseconds.
2022-10-21 17:16:00 +02:00
2023-02-11 19:18:50 +01:00
**Signature:**
2022-10-21 17:16:00 +02:00
```typescript
2023-09-27 07:31:47 +02:00
spawn(script: string, threadOrOptions?: number | SpawnOptions, ...args: (string | number | boolean)[]): void;
2022-10-21 17:16:00 +02:00
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| script | string | Filename of script to execute. |
2024-02-16 05:44:25 +01:00
| threadOrOptions | number \| [SpawnOptions ](./bitburner.spawnoptions.md ) | _(Optional)_ Either an integer number of threads for new script, or a [SpawnOptions ](./bitburner.spawnoptions.md ) object. Threads defaults to 1 and spawnDelay defaults to 10,000 ms. |
2022-10-21 17:16:00 +02:00
| args | (string \| number \| boolean)\[\] | Additional arguments to pass into the new script that is being run. |
2023-02-11 19:18:50 +01:00
**Returns:**
2022-10-21 17:16:00 +02:00
void
## Remarks
RAM cost: 2 GB
2023-09-27 07:31:47 +02:00
Terminates the current script, and then after a defined delay it will execute the newly-specified script. The purpose of this function is to execute a new script without being constrained by the RAM usage of the current one. This function can only be used to run scripts on the local server.
2022-10-21 17:16:00 +02:00
Because this function immediately terminates the script, it does not have a return value.
2023-03-21 23:54:49 +01:00
Running this function with 0 or fewer threads will cause a runtime error.
2022-10-21 17:16:00 +02:00
2023-02-14 07:32:01 +01:00
## Example
2022-10-21 17:16:00 +02:00
2023-02-14 07:32:01 +01:00
```js
2023-09-27 07:31:47 +02:00
//The following example will execute the script ‘ foo.js’ with 10 threads, in 500 milliseconds and the arguments ‘ foodnstuff’ and 90:
2024-02-16 05:44:25 +01:00
ns.spawn('foo.js', {threads: 10, spawnDelay: 500}, 'foodnstuff', 90);
2022-10-21 17:16:00 +02:00
```