Differences

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

Link to this comparison view

Next revision
Previous revision
component:computer:zh [2023/10/21 16:49]
hfsr created
component:computer:zh [2023/12/10 15:15] (current)
hfsr [组件:电脑]
Line 1: Line 1:
-Component: Computer+组件:电脑
 ================== ==================
-Computers provide a couple of API callbacks. Note that these can only be called by the computer itself, or its direct neighbors (i.e. other computers that share a face with that computer). Also note that since robots cannot interact with external components they cannot start/stop/query computers, but computers can interact with robots sitting next to them. +电脑提供了许多API回调。请注意这些函数只可以被电脑自身或与其直接相邻者(即与此电脑共面的电脑)调用。还请注意因为机器人不能与外界组件交互,它们也就不能关闭/开启电脑或查询其属性,不过电脑可以与其旁边的机器人交互。  ​ 
- +   
-Component name: `computer`  +组件名:`computer`。   
-Callbacks:+   
 +回调函数: ​
  
 - `start(): boolean`  ​ - `start(): boolean`  ​
-  ​Tries to start the computer. Returns ​`true` ​on success, ​`false` ​otherwise. Note that this will also return ​`false` ​if the computer was already running. If the computer is currently shutting down, this will cause the computer to reboot instead.+  ​尝试开启电脑。成功时返回`true`,否则返回`false`。请注意若电脑已经在运行,此函数也会返回`false`。若电脑正在关机过程中,此函数会使电脑改为重启。 ​  
 +\\
 - `stop(): boolean`  ​ - `stop(): boolean`  ​
-  ​Tries to stop the computer. Returns ​`true` ​on success, ​`false` ​otherwise. Also returns ​`false` ​if the computer is already stopped.+  ​尝试关闭电脑。成功时返回`true`,否则返回`false`。若电脑已经关闭也会返回`false`。   
 +\\
 - `isRunning():​ boolean`  ​ - `isRunning():​ boolean`  ​
-  ​Returns whether the computer is currently running.+  ​返回电脑当前是否正在运行。 ​  
 +\\
 - `beep([frequency:​number[,​ duration:​number]])`  ​ - `beep([frequency:​number[,​ duration:​number]])`  ​
-  ​Plays a tone, useful to alert users via audible feedback. Supports frequencies from 20 to 2000Hz, with a duration ​of up to seconds.+  ​播放一个声音,可用于以音频反馈的形式提醒用户。支持202000Hz的声音频率(`frequency`),长度(`duration`)最大为5秒。 ​  
 +\\
 - `getDeviceInfo():​ table`  ​ - `getDeviceInfo():​ table`  ​
-  ​Returns a table of device information. Note that this is architecture-specific and some may not implement it at all.+  ​返回包含设备信息的表。请注意此函数特定于架构,某些架构可能完全不会引入此函数。 ​  
 +\\
 - `crash(reason:​ string)`  ​ - `crash(reason:​ string)`  ​
-  ​Attempts to crash the computer for the specified reason.+  ​尝试以指定原因崩溃电脑。 ​  
 +\\
 - `getArchitecture():​ string`  ​ - `getArchitecture():​ string`  ​
-  ​Returns the computer'​s current architecture.+  ​返回电脑的当前架构。 ​  
 +\\
 - `isRobot(): boolean`  ​ - `isRobot(): boolean`  ​
-  ​Returns whether or not the computer is, in fact, a robot.+  ​返回此电脑是否为机器人。 ​  
 +\\ 
 + 
 +使用例:
  
-Example use: 
 ```lua ```lua
 local component = require("​component"​) local component = require("​component"​)
-local c = component.computer -- get primary computer, e.g. self +local c = component.computer --获取首选电脑组件,例如自身 
-print(c.isRunning()) -- definitely ​true if it's this computer +print(c.isRunning()) --如果c是这台电脑那当然为true 
-c.stop() -- basically like computer.shutdown() ​if it's this computer+c.stop() --如果c是这台电脑的话,大体相当于computer.shutdown()
 ``` ```