# OnInit

**OnInit** 事件在每个 [脚本加载项](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-1) 初始化时被调用一次。该事件会在程序启动时被调用，如果在 Opus 运行时添加或编辑脚本，也会被调用。实现 **OnInit** 事件是可选的，但强烈推荐，因为它允许您提供一个名称、描述和其它信息，以便在配置中向用户显示。它还为脚本提供了一种方式来 [添加内部命令](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_internal_command.zh) 和 [列](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_column.zh)（尽管 [**OnAddCommands**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onaddcommands.zh) 和 [**OnAddColumns**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh-1/onaddcolumns.zh) 方法提供了更好的方法来执行此操作）。

| **方法名称：** | OnInit                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **参数类型：** | [**ScriptInitData**](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-10/readme.zh-3/readme.zh/scriptinitdata.zh)                                                                                                                                                                                                                                                                                                                                                                                    |
| **返回类型：** | *bool*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| **描述：**   | 当 Opus 启动，或当脚本加载项被添加或编辑时，它的 **OnInit** 方法会被调用。这为脚本提供了一个机会，通过设置 **ScriptInitData** 对象的各种属性来告诉 Opus 有关自身的信息。**AddCommand** 方法也可以从该事件中使用来 [添加内部命令](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_internal_command.zh) 到 Opus 命令集中，AddColumn 方法可以用来添加 [列](https://chaoses-ib.gitbook.io/directory-opus/guan-fang-shou-ce/readme.zh-8/readme.zh-6/adding_a_new_column.zh)。 如果您从该方法返回 **True**，则脚本将被禁用，直到下次调用 **OnInit**（通常是在下次运行 Opus 时）。例如，如果 Windows 的版本不适合您的脚本，您可能需要这样做。 |
