RFTools Computercraft API

Betface

New Member
Jul 29, 2019
2
0
0
I've been playing around with Computercraft recently and discovered that it is possible to control RFTools Screens from a CC Computer, however I can't seem to find any info on the API that enlightens me as to how to use it effectively. As such, I figured I'd share my findings here so far and perhaps someone with more knowledge can enlighten us further?

In order to use the API, you will need:
- a CC computer placed next to an RFTools Screen Controller.
- one or more RFTools Computer Modules in the screen or screens you with to use.
- You will need to set a tag for each Computer Module that is easy to remember. (These can be the same tag, we'll come back to that later.)
- RFTools Screens connected to said Screen Controller.

The API at the moment has the following functions:

getScreenCount()
getScreenCoordinate(<intx>)
getScreenIndex(<intx>,<inty>,<intz>)
addText(<strA>,<strB>,<hex>)
setText(<strA>,<strB>,<hex>)
clearText(<strA>)

Here is what I have been able to glean about the functions so far:

getScreenCount()

Returns a count of all Screens connected to the Screen Controller

getScreenCoordinate(<intx>)

Returns the coordinates of the requested screen. <intx> is the number of the screen. I'm not sure in what order these are added.

getScreenIndex(<intx>,<inty>,<intz>)

Returns the index number of the screen at coordinates <intx>,<inty>,<intz>

addText(<strA>,<strB>,<hex>)

Adds text <strB> to the specified tag <strA> in the specified colour <hex>. This will not replace any existing text in the module, for that you will need the setText function.
For example, addText("tag1", "Hello World!", 0xFF5733) will add the text "Hello World!" (without quotes) to any screens with a Computer Module with the tag "tag1" (without quotes). The text here will be orange (0xFF5733).

setText(<strA>,<strB>,<hex>)

Sets any screens with the tag <strA> to display text <strB> in colour <hex>. See addText function description for more info.

clearText(<strA>)

Clears all text in any module with the tag <strA>.
For example, clearText("tag1") will clear all the text in any Screens with a Computer Module with the tag "tag1" (without quotes).

How to use this API:

You can access the API through the 'lua' shell on a CC computer. To do this:

- run 'lua' on the CC computer.
- type '<var> = peripheral.wrap(<direction>)' (without quotes) -- replace <var> with whichever variable name you would like to use, replace <direction> with the side of the computer your Screen Controller is connected to.
E.g. 'sc = peripheral.wrap("right")' (without single quotes)
- You now have access to any of the functions listed above. To set the text on a screen, type the following:
sc.setText("tag1", "Eureka!", 0x00ff00)
The above will display green text Eureka! on any screens tagged 'tag1'.

You can also use these functions in any programs you may wish to write. Enjoy!

NB I hope I am posting this in the right place and that this is useful information! If not, please can a moderator move it or something? I'm not wholly good with forums.