# SHost

**Members** 10

|          |                                                           |                                                                                                                                     |
| -------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Function | [InvokeEvent](#invokeevent)                               | Invokes a UnityEvent attached to the Scripting Runtime component this script is executing in.                                       |
| Function | [Stop](#stop)                                             | Pauses the current script until it is manually restarted, at the end of the current function/method; consider using return as well. |
| Function | [InvokeDelayed](#invokedelayed)                           | Invoke the closure after the delayed time.                                                                                          |
| Function | [StartCoroutine](#startcoroutine)                         | Executes the specified function as a coroutine.                                                                                     |
| Function | [ReferenceExists](#referenceexists)                       | Return true when the reference object exists and is not empty.                                                                      |
| Function | [ReferenceExistsAndNotEmpty](#referenceexistsandnotempty) | Return true when the reference object exists and is not empty.                                                                      |
| Function | [GetReference](#getreference)                             | Pulls a reference from the scripting runtime component's "References" section by it's name.                                         |
| Function | [Evaluate](#evaluate)                                     | Executes given Lua code/script. (white-label only)                                                                                  |
| Property | [ExecutingObject](#executingobject)                       | A reference to the GameObject that is executing this script. (The GameObject that this Scripting Runtime component is attached to). |
| Property | [Language](#language)                                     | Returns the English name for the users language, e.g. 'English', 'French', 'Chinese'                                                |

## Functions

### InvokeEvent

void InvokeEvent(string name)

Invokes a UnityEvent attached to the Scripting Runtime component this script is executing in.

Parameters

| Name | Type   | Default |
| ---- | ------ | ------- |
| name | string | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.InvokeEvent("EventName")

```

### Stop

void Stop()

Pauses the current script until it is manually restarted, at the end of the current function/method; consider using return as well.

Returns

`void`

Example

**Lua**

```lua
Space.Host.Stop()

```

**Lua**

```lua
local trans=Space.Host.ExecutingObject;
trans.SubscribeToEvents();

function Running()
    Space.Log("Running")
end

trans.OnUpdate(Running)

Space.Host.InvokeDelayed(function()
    Space.Log("Stop")
    Space.Host.Stop()
end,5)

--After print the "Stop","Running" won't display anymore.

```

### InvokeDelayed

void InvokeDelayed(Closure c, float delay)

Invoke the closure after the delayed time.

Parameters

| Name  | Type    | Default |
| ----- | ------- | ------- |
| c     | Closure | –       |
| delay | float   | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.InvokeDelayed(AFunction, 10)

```

**Lua**

```lua
--Clicking this object makes it destroy itself after 5 seconds
thisObject = Space.Host.ExecutingObject


function DeleteFunction()
  thisObject.Destroy()
end


function OnClickFunction()
  Space.Host.InvokeDelayed(DeleteFunction,10)
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)

```

### StartCoroutine

void StartCoroutine(DynValue value, DynValue parameter = default(DynValue), string name = null)

void StartCoroutine(string value, DynValue parameter = default(DynValue), string name = null)

Executes the specified function as a coroutine.

Parameters

| Name      | Type     | Default           |
| --------- | -------- | ----------------- |
| value     | DynValue | –                 |
| parameter | DynValue | default(DynValue) |
| name      | string   | null              |
| value     | string   | –                 |

Returns

`void`

Example

**Lua**

```lua
Space.Host.StartCoroutine(aFunction)
--or
Space.Host.StartCoroutine("aFunctionName")

```

**Lua**

```lua
local function myCoroutine()
    -- The yield statement is a special kind of return, that ensures that the function will continue from the line once the coroutine resumes.
    -- Placing a float value inside of the yield will result in a delayed execution.
    -- Example: coroutine.yield(0.5) will wait 0.5 seconds before continuing the execution of the coroutine.

    -- This will print the current players active time.
    Space.Log(Space.Time);

    -- Execution of this coroutine will be halted for 10 seconds.
    coroutine.yield(10);

    -- This will print the current players active time, which will be 10 seconds greater then the previous as a result of the yield
    Space.Log(Space.Time);
end

Space.Host.StartCoroutine(myCoroutine);

```

### ReferenceExists

bool ReferenceExists(string name)

Return true when the reference object exists and is not empty.

Parameters

| Name | Type   | Default |
| ---- | ------ | ------- |
| name | string | –       |

Returns

`bool`

Example

**Lua**

```lua
referenceExists = Space.Host.ReferenceExists("the reference name")

```

### ReferenceExistsAndNotEmpty

bool ReferenceExistsAndNotEmpty(string name)

Return true when the reference object exists and is not empty.

Parameters

| Name | Type   | Default |
| ---- | ------ | ------- |
| name | string | –       |

Returns

`bool`

Example

**Lua**

```lua
existsNotEmpty = Space.Host.ReferenceExistsAndNotEmpty("obj")
--Print "false" to console if didn't set the object named "obj" to the Object References or attach the reference to "obj".

```

### GetReference

[SGameObject](/docs/scripting/client-scripting-api-reference/types/sgameobject.md) GetReference(string name)

Pulls a reference from the scripting runtime component's "References" section by it's name.

Parameters

| Parameter | Type   | Description                                                                                   |
| --------- | ------ | --------------------------------------------------------------------------------------------- |
| name      | string | The name of the reference as set within the Scripting Runtime component (references section). |

Returns

`SGameObject`

Example

**Lua**

```lua
theObject = Space.Host.GetReference("referenceName")

```

**Lua**

```lua
--Clicking this object makes it destroy the object we linked in the references section
thisObject = Space.Host.ExecutingObject
dObject = Space.Host.GetReference("theObjectToBeDestroyed")

function OnClickFunction()
 dObject.Destroy()
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)

```

### Evaluate

void Evaluate(string script)

Executes given Lua code/script. (white-label only)

Parameters

| Name   | Type   | Default |
| ------ | ------ | ------- |
| script | string | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.Evaluate('Space.Log("test")')

```

## Properties

### ExecutingObject

[SGameObject](/docs/scripting/client-scripting-api-reference/types/sgameobject.md) ExecutingObject {get; }

A reference to the GameObject that is executing this script. (The GameObject that this Scripting Runtime component is attached to).

Example

**Lua**

```lua
object = Space.Host.ExecutingObject

```

### Language

string Language {get; }

Returns the English name for the users language, e.g. 'English', 'French', 'Chinese'

Example

**Lua**

```lua
lang = Space.Host.Language

```

**Lua**

```lua
--Makes a UIText show a different message according to the client's language
TextObject = Space.Host.GetReference("TextObject") --add to references section of Scripting Runtime component

language = Space.Host.Language


if language == "English" then
  TextObject.UIText.Text = "Welcome!"
elseif language == "Dutch" then
  TextObject.UIText.Text = "welkom!"
elseif language == "French" then
  TextObject.UIText.Text = "bienvenue!"
else
  TextObject.UIText.Text = "Welcome!"
end

```
