This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
okowsc's profile picture

Read Railcraft ticket from computercraft script

Started by okowsc, 11 September 2016 - 04:17 PM
okowsc #1
Posted 11 September 2016 - 06:17 PM
Hi there,
I am building a web app that my computercraft computers will use the HTTP api to connect to.
This web app will be brought up on a mobile device such as a phone or tablet next to the user whilst playing and will enable them to have buttons to control lights, unlock doors and turn on machinery.

I am able to have my computers poll ngrs.okonetwork.org.uk/action?id={computer_id} every second to obtain a list of what circuits need to be switched on or off, and actually switch them.

I would like to be able to have it so that a user can select a start station(second of railcraft track) and a destination station and have a train automatically switched and routed.
I have a php script that can take a start and destination station id and calculates what switches need switching, as it is possible to control railcraft switches with redstone i am able to have the computers switch the tracks but i do not know how to get sort sort of train id into my web app.

Is there any way to have Computercraft read the ticket of the railcraft locomotive as part of my script? If i could get the contents of the ticket i could give each locomotive a ticket with a unique id(something like 0001 0002 etc…) , have a computer near each switch read the id and switch tracks as appropriate and update my web app with the location of the train.

Thanks for advance for any help you can provide, it is greatly appreciated, i will be releasing all of my code and allowing people to access the web app free of charge when complete.
Edited on 11 September 2016 - 09:26 PM
Bomb Bloke #2
Posted 12 September 2016 - 01:43 AM
Is there any way to have Computercraft read the ticket of the railcraft locomotive as part of my script? If i could get the contents of the ticket i could give each locomotive a ticket with a unique id(something like 0001 0002 etc…) , have a computer near each switch read the id and switch tracks as appropriate and update my web app with the location of the train.

Speaking as one who knows next to nothing about Railcraft, I'd assume you shove these tickets into trains, and they change the train's NBT data in some way? Or are you intending to scan some sort of tile entity, like a chest or something?
okowsc #3
Posted 12 September 2016 - 09:14 AM
According to a a snippit of code i came across
NBTTagString dest = (NBTTagString) nbt.getTag("dest"); 
it appears to be something with NBT data.

Your right in thinking that you just put tickets into locomotives, you click on a locomotive to bring its GUI up and then drop the ticket into the slot.
Railcraft locomotives act for most purposes as minecarts, just self powered.
Bomb Bloke #4
Posted 12 September 2016 - 10:16 AM
In that case, it should be possible to read the data using a Command Computer and commands.entitydata(). The command is typically used to modify the NBT data of a targetted entity, but it's possible to leave it untouched (by passing in an empty table of attributes - {}), and the function also just happens to return the current NBT data as a string…

http://www.computercraft.info/forums2/index.php?/topic/22769-worldporter/page__view__findpost__p__252689

I'm afraid you probably won't like that answer (for starters, Command Computers require operators status to use - then there's the point that the entitydata command is unavailable to anything earlier than Minecraft 1.8…), but I'm unaware of any other way to read NBT data via ComputerCraft.

One day someone may make a sensor peripheral for the purpose, but AFAIK, that hasn't happened yet. Still, it may be worth trying a sensor on a train anyway? Who knows, that might turn up some other identifying bit of info.

http://www.computercraft.info/forums2/index.php?/topic/5996-mc-1710-cc-165-openccsensors/
okowsc #5
Posted 12 September 2016 - 12:23 PM
By the way what do you think about the idea of a Web app to control in game stuff?
okowsc #6
Posted 12 September 2016 - 03:20 PM
Thanks for your help.
Turns out a OpenCC sensor with a minecart MK1 sensor card actually gives the RouteDestination from the ticket.
I now have the routedestination as a string in my script,just got to send it to my web app :)/>