Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
api:component:zh [2023/10/17 10:21]
hfsr [Component API]
api:component:zh [2023/10/17 10:42]
hfsr [Component(组件) API]
Line 1: Line 1:
 Component(组件) API Component(组件) API
 ============= =============
-component(组件) API可用于访问电脑中的组件并与其交互。读者还可查看[[:​component:​component_access:​zh|有关组件交互的页面]]。+component(组件) API可用于访问电脑中的组件并与其交互。读者还可查看[[:​component:​component_access:​zh|有关访问组件的页面]]。
  
 - `component.doc(address:​string,​ method:​string):​ string`  ​ - `component.doc(address:​string,​ method:​string):​ string`  ​
Line 14: Line 14:
   返回一张表,其中包含指定地址的组件提供的所有方法名。表中的键为方法名,而表中的值代表了此方法是否为直接调用。   返回一张表,其中包含指定地址的组件提供的所有方法名。表中的键为方法名,而表中的值代表了此方法是否为直接调用。
 - `component.proxy(address:​string):​table`  ​ - `component.proxy(address:​string):​table`  ​
-  获取某组件的'​proxy'​对象(代理对象),代理对象将组件提供的所有方法以键值对的形式给出,因此可以更直接地调用它们(无需通过`invoke`)。这也是用来生成各个组件类型的“首选组件”的方法,也即你通过`component.某某`(某某为组件类型)方法得到的东西。+  获取某组件的'​proxy'​对象(代理对象),代理对象将组件提供的所有方法以字段(键值对的形式给出,因此可以更直接地调用它们(无需通过`invoke`)。这也是用来生成各个组件类型的“首选组件”的方法,也即你通过`component.某某`(某某为组件类型)方法得到的东西。
   例如,你可以这样使用此方法:`component.proxy(component.list("​redstone"​)()).getInput(sides.north)`,这段代码会为你获取`component.list`迭代器返回的第一个`redstone`组件的代理对象,然后调用它的`getInput`方法。   例如,你可以这样使用此方法:`component.proxy(component.list("​redstone"​)()).getInput(sides.north)`,这段代码会为你获取`component.list`迭代器返回的第一个`redstone`组件的代理对象,然后调用它的`getInput`方法。
-  请注意代理对象无论如何都至少有两个键值对:一是`type`与组件的类型名,二是`address`与组件的地址。+  请注意代理对象无论如何都至少有两个字段:一是`type`与组件的类型名,二是`address`与组件的地址。
 - `component.type(address:​string):​string`  ​ - `component.type(address:​string):​string`  ​
   获取指定地址的组件的类型。   获取指定地址的组件的类型。