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

Ticket System can someone help

Started by russ155, 12 October 2012 - 02:25 PM
russ155 #1
Posted 12 October 2012 - 04:25 PM
Hello

I'm new to these forums so am not sure if I'm in the right place.

Basically my problem is that I want to make a system on computercraft so when a floppy with the label "Ticket" is inserted it disables a redstone signal which is allready running keeping the gate closed and then when the disk is put in it stops the redstone signal opening the gate or stopping the redstone signal before giving the person back their ticket waiting 5 secconds and restarting the redstone signal.

Any help will be much appreciated
Thanks
Doyle3694 #2
Posted 12 October 2012 - 04:43 PM
Try coding what you can yourself and come back when you get a concrete problem. we are here to help, not code for you :)/>/>
GopherAtl #3
Posted 12 October 2012 - 04:55 PM
"redstone.setOutput("back",true)" will turn on the redstone on the back. Change back to whatever side you want, and change true to false to turn it off instead of on.

"sleep(1)" will sleep, i.e., do nothing, for 1 second. Change 1 to whatever you want.

"local event, side = os.pullEvent("disk")" will wait for a disk event, which happens when a disk is inserted. event will equal "disk" and side will be the side of the computer the disk drive is on.

"disk.getLabel(side)" will get the label of the disk in the drive on "side."

"disk.eject(side)" will eject the disk from the drive on "side."

All this helpful info and more can be found on the wiki.
Lyqyd #4
Posted 12 October 2012 - 05:43 PM
Also, you're going to want to use a torch on the side of the computer for the output (or otherwise invert the signal), so that if the computer is turned off, the signal will remain on.
russ155 #5
Posted 12 October 2012 - 07:08 PM
Thanks a lot il just test it
russ155 #6
Posted 12 October 2012 - 07:43 PM
It doesnt seem to work but me and my friend have thought of another solution
Cranium #7
Posted 12 October 2012 - 08:01 PM
It will work, as I have used it to great effect before. What have you got so far?
russ155 #8
Posted 18 October 2012 - 09:24 PM
I have fixed it now and Iv now trying to get my head around bundled cables I would like a monitor to display after you enter the park what rides are open this is what I have so far but it doesn't work:

os.pullEvent()
print(redstone.getInput(bottom))
if true do
print("The Giant Coaster. OPEN")
else
print("The Giant Coaster. CLOSED")
end

Any ideas on how I can get this to check if a redstone signal is on .. on say blue and then display open but change to closed if the signal ends.

Any help will be greatly appreciated
remiX #9
Posted 18 October 2012 - 09:41 PM
rs.getInput("side") will return true if there is a redstone signal coming from 'side'


if rs.getInput("bottom") then
  print("The Giant Coaster. OPEN")
else
  print("The Giant Coaster. CLOSED")
end

EDIT:

If you want to check the status of the redstone signal constantly use a while true loop:


while true do
  term.clear()
  term.setCursorPos(1,1)
  if rs.getInput("bottom") then
	print("The Giant Coaster. OPEN")
  else
	print("The Giant Coaster. CLOSED")
  end
end
Lyqyd #10
Posted 18 October 2012 - 11:56 PM
That loop needs an os.pullEvent("redstone") at the top to both prevent going too long without yielding and also to only bother re-drawing when there has been a change.
remiX #11
Posted 19 October 2012 - 02:28 PM
Oh yeah, I forgot to add a sleep(0). It skipped my mind.
Lyqyd #12
Posted 19 October 2012 - 03:49 PM
Oh yeah, I forgot to add a sleep(0). It skipped my mind.

sleep(0) would be an inferior solution in this case, since there is no need to redraw the screen unless the status of something changes. Constantly redrawing could easily cause lag in multiplayer environments.
remiX #13
Posted 19 October 2012 - 07:51 PM
Oh yeah, I forgot to add a sleep(0). It skipped my mind.

sleep(0) would be an inferior solution in this case, since there is no need to redraw the screen unless the status of something changes. Constantly redrawing could easily cause lag in multiplayer environments.

Because of the clear(). Well I've been doing this in all my codes. How do I prevent this?
Lyqyd #14
Posted 19 October 2012 - 08:03 PM
Oh yeah, I forgot to add a sleep(0). It skipped my mind.

sleep(0) would be an inferior solution in this case, since there is no need to redraw the screen unless the status of something changes. Constantly redrawing could easily cause lag in multiplayer environments.

Because of the clear(). Well I've been doing this in all my codes. How do I prevent this?

The clear() isn't any worse than the rest of the writes, but doing it all constantly is bad. Make sure to re-draw only when the values you are drawing change, by watching for the events that change them.
russ155 #15
Posted 19 October 2012 - 08:03 PM
I was hoping to find out how to do it with bundled cable so i can get the computer to display whether various rides are open any idea's ?????? i would like it so that if i also had the waterpark light on and wanted to close the giant coaster it would display closed on the giant coaster but leave the waterpark as open
Any idea's will be very helpful
ChunLing #16
Posted 19 October 2012 - 08:49 PM
Honestly, if you use rednet.send rather than rednet.broadcast, it's just as secure as cable and a lot less hassle. Just my opinion.

But I believe that the sending of rednet over buildcraft cables is still supported, if you want to use cables. There is also a peripheral mod that adds peripheral cables if what you want is a single computer controlling several monitors that are in different locations…though the cost of the cable makes me think that it would usually just be cheaper to use a rednet slaved computer at each monitor.
russ155 #17
Posted 19 October 2012 - 09:48 PM
Thats a great idea and I will certanly look into it as that could be very useful the thing is though I don't really understand and from what iv seen bundled cable is simpler the problem is I would just like a really basic tutorial or explanation on how to use it. Its because at the front of our theme park we have the ticket system which I have now perfected then we have a big monitor which I would like to display what rides are open and closed but we want to be able to control which rides are open and shut from our server office that's why I would like to use bundled cable
Lyqyd #18
Posted 19 October 2012 - 09:50 PM
Honestly, if you use rednet.send rather than rednet.broadcast, it's just as secure as cable and a lot less hassle. Just my opinion.

But I believe that the sending of rednet over buildcraft cables is still supported, if you want to use cables. There is also a peripheral mod that adds peripheral cables if what you want is a single computer controlling several monitors that are in different locations…though the cost of the cable makes me think that it would usually just be cheaper to use a rednet slaved computer at each monitor.

He's referring to redpower's bundled cables, I believe.

To OP: check out the redstone API on the wiki, especially the redstone.testBundledInput function.
ChunLing #19
Posted 20 October 2012 - 12:39 AM
Yeah…probably. I don't use them so I get mixed up some.
russ155 #20
Posted 20 October 2012 - 07:08 PM
i tried thatr but its really complicated and i dont understand it i would like a code which i can see the basics of how it works and then be able to write my own codes from that
is anybody able to help with that
ChunLing #21
Posted 20 October 2012 - 08:33 PM
Wait, what part didn't you understand? We were sorta wandering a bit there.
russ155 #22
Posted 20 October 2012 - 09:57 PM
I don't really understand rednet I have only just started with computercraft I would mostly like to use bundled cable the problem is I just get lost in the api's because hwat I want is to have a bundled cable coming into the computer and then have a redstone signal on say blue that would then display "open" but if the signal went off it would show "closed" but I would like it to do that with various colours
Any help will be very useful
ChunLing #23
Posted 20 October 2012 - 10:25 PM
Oh…the thing is, you still have to use rednet whether you want to use cables or modems.

I mean, I guess you could implement some kind of pulsed redstone output code, but that strikes me as a lot more difficult than using the rednet API. It's actually pretty simple. You open the side where the modem or cable is attached using rednet.open(side) (where side is a string), then you can use rednet.send(ID,message) (ID is a number ID of the receiving computer, message is a string that will be sent) or rednet.broadcast(message) (to send to all computers able to receive), then rednet.receive(timeout) (timeout is how long to wait for a message) returns the sender's ID and the message if it gets a message before timeout, or returns nil (if no timeout is specified, the computer will wait forever if need be–or until you terminate the program somehow).

Here's a simple rednet opening function for modems:
local function opnmdm()
    for i,v in pairs(rs.getSides()) do    
        if peripheral.getType(v) == "modem" then
            if not rednet.isOpen(v) then rednet.open(v) end
        return true end
    end
return false end
I'm not sure what the peripheral type of bundled cable is, or even if it has one. Anyway, with the above function, you can make a simple program like so:
if not opnmdm() then print("Modem Access Error") return false end
local rcID,tvnt = nil
repeat print("Enter receiver ID> ")
    rcID = tonumber(read())
until rcID
print("Press Shift+S to send message to "..rcID)
print("Press Shift+R to change receiver ID")
print("Change receiver ID to nil to exit")
while rcID do
    tvnt = {os.pullEvent()}
    if tvnt[1] == "rednet_message" then print(tvnt[2]..": "..tvnt[3])
        if tvnt[3]:find("^send") then rednet.send(tvnt[2],read()) end
    elseif tvnt[2] == "S" then write("Enter message> ") rednet.send(rcID,read())
    elseif tvnt[2] == "R" then write("Enter new receiver ID> ") rcID = tonumber(read()) end
end 
What this does is check all the sides for a modem using the above function, turning on the modem and continuing the program if there is one or exiting if there isn't. It then asks you for an ID (a number) to be the receiver. Then it loops, pulling an event, and printing out the event if it's a rednet message, or allowing you to enter a message or change the receiver if you press Shift+S or Shift+R.

This is, of course, just so that you can get the idea of how rednet messages are sent and received. Though you can use it to do some messaging, or for remote control of another computer that's set up to respond to rednet messages as commands rather than just printing them out.
Lyqyd #24
Posted 21 October 2012 - 12:05 AM
You are completely off-base, ChunLing. He just wants to check steady redstone signals being input to represent the states of various things that need to be written to the monitor. As I said earlier, this can be very simply accomplished using a loop that waits for a redstone event, then re-draws the monitor using redstone.testBundledInput() to check each wire color's state.
ChunLing #25
Posted 21 October 2012 - 04:12 AM
Hmm…I guess I fail at cables.
russ155 #26
Posted 21 October 2012 - 10:34 AM
That is exactly what I want to do Lyqyd but I don't know how to code it could you give me a code which i could use to check the colour Green for a redstone signal and then display "The Dropper OPEN"
but if the signal stops display "The Dropper CLOSED"
I would really appreciate that as I can then see what I need to do for the other 5 colours.
Thanks
Lyqyd #27
Posted 21 October 2012 - 05:41 PM
That is exactly what I want to do Lyqyd but I don't know how to code it could you give me a code which i could use to check the colour Green for a redstone signal and then display "The Dropper OPEN"
but if the signal stops display "The Dropper CLOSED"
I would really appreciate that as I can then see what I need to do for the other 5 colours.
Thanks

This really is very simple.


term.redirect(peripheral.wrap("top")) --sets output to top monitor
while true do
  os.pullEvent("redstone") --waits for a change in redstone inputs
  term.clear()
  term.setCursorPos(1,1)
  print("Ride Status:")
  if rs.testBundledInput("back", colors.green) then
    --green is on, ride is open
    print("Awesome ride: OPEN")
  else
    --green is off, ride is closed
    print("Awesome ride: CLOSED")
  end
  --more rides here
end
ChunLing #28
Posted 21 October 2012 - 08:31 PM
You might want to put the result of peripheral.wrap("top") into a variable rather than use it directly like that, in case you want to do things like change the text size and stuff. I have no experience with the cable functions, but I trust they work.
russ155 #29
Posted 21 October 2012 - 09:32 PM
Thank you so much this will be really useful to me