Jump to content




Working with Railcraft

help

87 replies to this topic

#1 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 19 January 2013 - 11:11 PM

I want to make a train network and have it fully intergrated with computercraft.
I did see a post somewhere on a website (might have been this one) talking about something like this but I cant find it anywhere.

What I'm looking for is for people to help point me in the right direction for writing the programs and setting it up. I want to learn how to do it as I go along. Thought I would start with a small project as my first lol ;-)

Here is a list of what I want/think my system to do:
  • Train Status Board - This will show if a train is at a platform and where that platform will take you
  • Route planning system - When a player gets into a train and presses the go button that signal will tell the "points" how to change so it goes to the right track
  • Train Location Board - This will be for the control room and will show what a train is doing, so for example the train from Pitsea to Basildon is heading to Basildon and the train from Southend to Grays is waiting at grays.
I'm sure there are lots more things I could add but these seem fairly massive so lets start with them.

The train station will work like a real one where players will have to wait for a train to arrive rather than calling a personal train.

I'm not sure if im going to have more than one stop per line and have the train wait for "x" time and then carry on just like real trains.

So any hints/help/ideas please.

#2 dan14941

  • Members
  • 45 posts

Posted 20 January 2013 - 02:29 AM

You would have to connect your computers to redstone and monitors and wireless modems if you want this to work as I am not good with rednet I can't help you with that sorry but if you don't know how to make your computer output a redstone signal just ask me!

Ps if you found this helpful click my green "/\" in the corner
|

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 02:38 AM

I'm not too sure, but I'm pretty sure that RailCraft is entirely redstone based meaning you will need to look here ( http://computercraft...e=Redstone_(API) ) and checkout how to use the redstone functionality of computers.

As for things such as displaying data about trains on platforms and such your best option is to use Rednet to transmit data around your world between computers. Info on the rednet API can be found here ( http://computercraft...tle=Rednet_(API) ).

For displaying data on monitors you will want to take a look into the peripherals API here ( http://computercraft...Peripheral_(API) ).

There will also need to be some kind of data persistence so you will want to look here ( http://computercraft...p?title=IO_(API) ) and here ( http://computercraft...p?title=Fs_(API) ) and chapter 21 here ( http://www.lua.org/pil/21.html )

If there is anything else you need help with just ask. Feel free to post any code you have done to pastebin to get assistance with any issues quicker too.

#4 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 04:03 AM

For the display I plan to use the signal from the Railcraft Signals via bundled wire to show the redstone state.
print (redstone.getBundledInput("back"), colors.blue)
if = "true"
print ("+++++++")
else
print ("----------")

The above code is not right I know, but its just showing my thinking. On the monitor I want the train shown with ++++++++ and the track show with -------- that way I can show the progress of the train. I would like to have two types of trains with the highspeed train displayed as ******** but this might get too messy on the screen.
I dont have the advanced monitors as they are not part of techic classic.

Am I thinking in the right direction?

#5 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 04:53 AM

While x ~= "pie" dp
y = rs.getBundledInput("back")
sleep(1)
if colors.test (y, colors.lime) == true then
print ("++++++++")
sleep(1)
else
if colors.test (y, colors.lime == false then
print ("--------")
sleep(1)
end
end

I found this code here: http://www.computerc...ed-cable-basics

Now I have no idea what the top line means, but he says it makes it repeat. The bottom bit with the prints is what I want it to do, but again I'm not sure if thats right. I hope to upload a picture of what the display will look like to help explain what I'm trying to do.

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 04:58 AM

if you want your program to infinitely loop use this at the top instead of what you have
while true do

this means that the program will continue to run forever until it is either terminated by a user, errors, or the computer is shutdown or rebooted...

So if I'm understanding you correctly the 'trains' are tracked by signal boxes which can output a redstone signal when a 'train' is near by... is that right? ( sorry for the questions, I've never actually used RailCraft's advanced features before, I've always been CC or RP2... )

#7 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 08:59 AM

Yes in railcraft you have sensors that can detect when a train is between them and output redstone for things like this and also to switch tracks if the track ahead is blocked or hold the train etc.
I will have sensors on each part of my track and check the redstone state of the stations so I can track them there too.
Here is what the display of the "map" will look like:
Posted Image

Key:
- = Empty Track
+ = Train on Track
@ = Empty Station
* = Train at Station

#8 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 10:49 AM

View Postredeye83, on 20 January 2013 - 08:59 AM, said:

Yes in railcraft you have sensors that can detect when a train is between them and output redstone for things like this and also to switch tracks if the track ahead is blocked or hold the train etc.
I will have sensors on each part of my track and check the redstone state of the stations so I can track them there too.
Here is what the display of the "map" will look like:
Posted Image

Key:
- = Empty Track
+ = Train on Track
@ = Empty Station
* = Train at Station
Yeh ok then, given that its completely possible to do. My main concern was that you were going to have no way to know where the trains were... But you can have it show different chars to the screen too. You will definetly need to look into rednet ( since I'm assuming that track is over quite a large distance ) and the redstone API for the bundled cable control.

#9 dan14941

  • Members
  • 45 posts

Posted 20 January 2013 - 12:15 PM

you could use the sensors to send redstone inputs to the commuter and have the computer display it on a monitor

#10 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 04:15 PM

View Postdan14941, on 20 January 2013 - 12:15 PM, said:

you could use the sensors to send redstone inputs to the commuter and have the computer display it on a monitor
Yep thats the plan, does anyone know the range of wireless redstone? I would be so much easyer if I could just use that rather than rednet.

#11 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 05:04 PM

View Postredeye83, on 20 January 2013 - 04:15 PM, said:

View Postdan14941, on 20 January 2013 - 12:15 PM, said:

you could use the sensors to send redstone inputs to the commuter and have the computer display it on a monitor
Yep thats the plan, does anyone know the range of wireless redstone? I would be so much easyer if I could just use that rather than rednet.
I don't think it has one... I think... Did I say I think :P
I'm pretty sure using rednet on a RP2 bundled cable allows it to go further than normal too...

#12 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 20 January 2013 - 08:16 PM

View Postredeye83, on 20 January 2013 - 04:15 PM, said:

View Postdan14941, on 20 January 2013 - 12:15 PM, said:

you could use the sensors to send redstone inputs to the commuter and have the computer display it on a monitor
Yep thats the plan, does anyone know the range of wireless redstone? I would be so much easyer if I could just use that rather than rednet.

When I use to play tekkit Classic I tested and it worked for 250 blocks, after that I got over testing because that's wayyy more than I needed :P
Not sure about FTB, Tekkit Lite, though.

#13 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 08:54 PM

View PostremiX, on 20 January 2013 - 08:16 PM, said:

View Postredeye83, on 20 January 2013 - 04:15 PM, said:

View Postdan14941, on 20 January 2013 - 12:15 PM, said:

you could use the sensors to send redstone inputs to the commuter and have the computer display it on a monitor
Yep thats the plan, does anyone know the range of wireless redstone? I would be so much easyer if I could just use that rather than rednet.

When I use to play tekkit Classic I tested and it worked for 250 blocks, after that I got over testing because that's wayyy more than I needed :P
Not sure about FTB, Tekkit Lite, though.
I'm running Tekki Classic on my server so it should be fine but to be honest I'm most likly going to use wireless redstone as it takes less time lol

#14 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 09:22 PM

local monitor = peripheral.wrap("back")
monitor.clear()
while true do
y = rs.getBundledInput("back") 
sleep(1) 
if colors.test (y, colors.purple) == true then 
print ("*----@----@----@----@") 
sleep(1) 
else 
if colors.test (y, colors.purple) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
sleep(1) 
if colors.test (y, colors.red) == true then 
print ("@++++@----@----@----@") 
sleep(1) 
else 
if colors.test (y, colors.red) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.orange) == true then 
print ("@----*----@----@----@") 
sleep(1) 
else 
if colors.test (y, colors.orange) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.white) == true then 
print ("@----@++++@----@----@") 
sleep(1) 
else 
if colors.test (y, colors.white) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.lime) == true then 
print ("@----@----*----@----@") 
sleep(1) 
else 
if colors.test (y, colors.lime) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.blue) == true then 
print ("@----@----@++++@----@") 
sleep(1) 
else 
if colors.test (y, colors.blue) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.cyan) == true then 
print ("@----@----@----*----@") 
sleep(1) 
else 
if colors.test (y, colors.cyan) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.black) == true then 
print ("@----@----@----@++++@") 
sleep(1) 
else 
if colors.test (y, colors.black) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end 
if colors.test (y, colors.magenta) == true then 
print ("@----@----@----@----*") 
sleep(1) 
else 
if colors.test (y, colors.magenta) == false then 
print ("@----@----@----@----@") 
sleep(1) 
end
if colors.test (y, colors.pink) == true then 
print ("	 +		 /") 
sleep(1) 
else 
if colors.test (y, colors.pink) == false then 
print ("	 \		 /") 
sleep(1) 
end
if colors.test (y, colors.green) == true then 
print ("	 \		 +") 
sleep(1) 
else 
if colors.test (y, colors.green) == false then 
print ("	 \		 /") 
sleep(1) 
end
if colors.test (y, colors.pink) == true then 
print ("	  +	   /") 
sleep(1) 
else 
if colors.test (y, colors.pink) == false then 
print ("	  \	   /") 
sleep(1) 
end
if colors.test (y, colors.green) == true then 
print ("	  \	   +") 
sleep(1) 
else 
if colors.test (y, colors.green) == false then 
print ("	  \	   /") 
sleep(1) 
end
if colors.test (y, colors.brown) == true then 
print ("	   *-----@") 
sleep(1) 
else 
if colors.test (y, colors.brown) == false then 
print ("	   @-----@") 
sleep(1) 
end
if colors.test (y, colors.yellow) == true then 
print ("	   @+++++@") 
sleep(1) 
else 
if colors.test (y, colors.yellow) == false then 
print ("	   @-----@") 
sleep(1) 
end
if colors.test (y, colors.gray) == true then 
print ("	   @-----*") 
sleep(1) 
else 
if colors.test (y, colors.gray) == false then 
print ("	   @-----@") 
sleep(1) 
end	 
end
Ok this is the baisc code that I've come up with, whats missing? I've not tested this yet as I'm at work (shhh dont tell the boss) but would like to sort out the code so i can test it as soon as I get home.

#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 09:33 PM

View Postredeye83, on 20 January 2013 - 09:22 PM, said:

Ok this is the baisc code that I've come up with, whats missing? I've not tested this yet as I'm at work (shhh dont tell the boss) but would like to sort out the code so i can test it as soon as I get home.
A monitor and a bundled cable can't be on the same side as a computer and the syntax for elseif's in lua is
if <condition> then
  -- code
elseif <condition> then
  -- code
elseif <condition> then
  -- code
end

That being said your if else statements are a little confusing in the first place with the logic behind them...

EDIT: Also thats a lot of sleeps!!!! :P

Edited by TheOriginalBIT, 20 January 2013 - 09:40 PM.


#16 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 09:46 PM

thats a very good point I didnt realise they were both set to back lol. As for the logic of my if's there is no real logic, I know what I want but I'm not 100% sure how to do it lol.
if colors.test (y, colors.gray) == true then 
print ("		   @-----*") 
sleep(1) 
else 
if colors.test (y, colors.gray) == false then 
print ("		   @-----@") 
sleep(1) 
end  
so this bit to ME means that if the gray wire gets power it will print what I want and if its not got power it will print the other line and will keep checking every second to see if it has a signal. This is so that the map is live. I then just copy and repeated this. The one thing I may have a problem with is getting it to display on the lines/rows I want it to like it does in the picture above.

#17 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 09:53 PM

ok so before I suggest some improved logic... the colours will be the location of the train on the map? or the type of train it is?
to set the cursor location for printing you can use
term.setCursorPos( x, y )
where x and y are the location on the screen you wish to set it to.

also side note here that code will take a minimum of FAR more than 1 second...

EDIT: oh another thing I just noticed, it will never print to the monitor... you have to redirect the computer to the monitor if you wish to use the print function to print to the monitor
-- after you have wrapped the monitor and want to print to it
term.redirect( monitor )

-- all your program code here

-- at the very end of the program ( or when you want to print on the computer again )
term.restore()

Edited by TheOriginalBIT, 20 January 2013 - 09:55 PM.


#18 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 20 January 2013 - 10:12 PM

The colors are for the parts of the map, so Purple is the first Station and Red is the first bit of track. They will change to show where the train is.

so would

term.setCursorPos(1,1)
if colors.test (y, colors.magenta) == true then
print ("@----@----@----@----*")
os.pullEvent()
else
if colors.test (y, colors.magenta) == false then
print ("@----@----@----@----@")
os.pullEvent()
end
term.setCursorPos(1,2)
if colors.test (y, colors.pink) == true then
print ("	 +		 /")
os.pullEvent()
else
if colors.test (y, colors.pink) == false then
print ("	 \		 /")
os.pullEvent()
end

Make the output from the pink wire's response go to the next line?

Also I changed the sleep to a pullEvent, would that work?



#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 January 2013 - 10:24 PM

View Postredeye83, on 20 January 2013 - 10:12 PM, said:

The colors are for the parts of the map, so Purple is the first Station and Red is the first bit of track. They will change to show where the train is.

Make the output from the pink wire's response go to the next line?

Also I changed the sleep to a pullEvent, would that work?

Print actually automatically goes to the next line for you... but this is a basic form of how you would do it ( I'm following the same pattern you have for your strings to print, these may need to change later so one string doesn't write over another )...

while true do -- loop forever, unless of error or termination by the user
  term.clear() -- clear the screen for printing
  term.setCursorPos(1,1) -- put the cursor in the top left
  if colors.test( y, colours.magenta ) then
	print("@----@----@----@----*")
  else
	print("@----@----@----@----*")
  end

  if colors.test( y, colors.pink ) then
	print("		 +			   /")
  else
	print("		 \\			   /") -- this needs \\ here because \ is whats known as an escape character
  end

  -- etc, etc, etc

  sleep( 1 ) -- sleep for a second at the VERY END of drawing the whole screen...
end


#20 redeye83

  • Members
  • 202 posts
  • LocationUnited Kingdom

Posted 21 January 2013 - 12:21 AM

Ok I've now managed to confuse myself by trying to work out a question lol.
Basicly If i set the cursor to 1,1 for the first line can I just add the cursor set code but have 1,2 on the if bits so they display on the second line and format right?

Also someone ^^^^ sugested I use FTB for my server so that means I will have Advanced Colour scrrens, where can I find out how to make my code even more complicated with color? lol





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users