# SScriptingRuntime

**成员** 10

|      |                                           |                                                           |
| ---- | ----------------------------------------- | --------------------------------------------------------- |
| 函数 | [GetResource](#getresource)               | Get the resource by its name and return it.               |
| 函数 | [CallScriptFunction](#callscriptfunction) | Call registered script function with specified arguments. |
| 函数 | [Reset](#reset)                           | Reset event members to their initial values.              |
| 函数 | [GetPublicVariable](#getpublicvariable)   | Gets the public variable by its name and return it.       |
| 函数 | [SetPublicVariable](#setpublicvariable)   | Set the property to public variable with name "name".     |
| 函数 | [InvokeEvent](#invokeevent)               | Invokes the event with the name "name".                   |
| 属性 | [Resources](#resources)                   | Return a list of resource.                                |
| 属性 | [Enabled](#enabled)                       | Whether the scripting runtime component is Enabled.       |
| 属性 | [ComponentName](#componentname)           | The name of this component.                               |
| 属性 | [GameObject](#gameobject)                 | –                                                         |

## 函数

### GetResource

[SResource](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sresource.md) GetResource(string name)

Get the resource by its name and return it.

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SResource`

示例

**Lua**

```lua
resource = Space.Host.ExecutingObject.Script.GetResource("resource name")

```

### CallScriptFunction

void CallScriptFunction(string name, params DynValue\[] arguments)

void CallScriptFunction(string name)

Call registered script function with specified arguments.

参数

| 名称      | 类型               | 默认值 |
| --------- | ------------------ | ------ |
| name      | string             | –      |
| arguments | params DynValue\[] | –      |

返回值

`void`

示例

**Lua**

```lua
resource = Space.Host.ExecutingObject.Script.CallScriptFunction("FunctionName")
--or
resource = Space.Host.ExecutingObject.Script.CallScriptFunction("FunctionName", tableWithArguments)

```

### Reset

void Reset()

Reset event members to their initial values.

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.Script.Reset()

```

### GetPublicVariable

object GetPublicVariable(string name)

Gets the public variable by its name and return it.

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`object`

示例

**Lua**

```lua
publicVariable = Space.Host.ExecutingObject.Script.GetPublicVariable("variableName")

```

### SetPublicVariable

void SetPublicVariable(string name, DynValue property, bool persistent = false)

Set the property to public variable with name "name".

参数

| 名称       | 类型     | 默认值 |
| ---------- | -------- | ------ |
| name       | string   | –      |
| property   | DynValue | –      |
| persistent | bool     | false  |

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.Script.SetPublicVariable("VariableName",5,true)

```

### InvokeEvent

void InvokeEvent(string name)

Invokes the event with the name "name".

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`void`

示例

**Lua**

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

```

## 属性

### Resources

[SResource](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sresource.md)\[] Resources {get; }

Return a list of resource.

示例

**Lua**

```lua
tableResources = Space.Host.ExecutingObject.Script.Resources

```

### Enabled

bool Enabled {get; set; }

Whether the scripting runtime component is Enabled.

示例

**Lua**

```lua
Space.Host.ExecutingObject.Script.Enabled = true

```

### ComponentName

string ComponentName {get; }

The name of this component.

示例

**Lua**

```lua
componentName = Space.Host.ExecutingObject.Script.ComponentName

```

### GameObject

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

示例

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.Script.GameObject

```
