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

Some help with my ticket printing function

Started by Cranium, 29 July 2012 - 02:03 AM
Cranium #1
Posted 29 July 2012 - 04:03 AM
I want to have my computer attached to a disk drive to just print the label of the destination on the disk, using a function. The problem is, my tickets keep being printed out either with a label of nil, or coming out blank. I have no idea how I'm supposed to have this done, because the variables I need to enter when calling, need to be the label of the ticket. Here's what I have so far:

function pticket(name)
    rs.setOutput("back", true)
	 sleep(.5)
    rs.setOutput("back", false)
	 sleep(1)
    disk.setLabel("bottom", name)
    print("Thank you, your ticket will now print")
	 sleep(2)
    disk.eject("bottom")
    term.clear()
    term.setCursorPos(1,8)
    print("Your ticket has been printed.")
    print("Please redeem at next station")
	 sleep(2)
    os.reboot()
end
Xenthera #2
Posted 29 July 2012 - 04:11 AM

function pticket(name)
    rs.setOutput("back", true)
		 sleep(.5)
    rs.setOutput("back", false)
		 sleep(1)
    disk.setLabel("bottom", name)
    print("Thank you, your ticket will now print")
		 sleep(2)
    disk.eject("bottom")
    term.clear()
    term.setCursorPos(1,8)
    print("Your ticket has been printed.")
    print("Please redeem at next station")
		 sleep(2)
    os.reboot()
end
name = io.read()
pticket(name)

You will enter something, it will 'print' or label rather, the disk with what you typed. Then Eject it. I THINK that's what you were asking…
Cranium #3
Posted 29 July 2012 - 04:15 AM
Not quite. I have a menu system that you must select the destination, then if you select one destination, I had it set to call back to the function like this:

select = read()
if select == "1" then
pticket(destination1)
end
If it worked like I had wanted it to, it would print the disk with label "destination1"

Edit: If you need to, I can post my whole code for analysis.
Edited on 29 July 2012 - 02:15 AM
Xenthera #4
Posted 29 July 2012 - 04:15 AM
destination1 is currently a variable with nothing assigned to it. Thus giving you 'nil'. You have to set destination1 as a string.
Xenthera #5
Posted 29 July 2012 - 04:19 AM
Yeah Post your whole code.
Cranium #6
Posted 29 July 2012 - 04:23 AM
destination1 is currently a variable with nothing assigned to it. Thus giving you 'nil'. You have to set destination1 as a string.
So for example, I would enter:
pticket(tostring(destination1))
so it would turn that into a string?

Edit: just gonna put this here:


-- screen functions
function tymsg()
mon.clear()
mon.setCursorPos(1,1)
mon.write(" Thank")
sleep(2)
mon.setCursorPos(1,2)
mon.write("  You")
sleep(2)
mon.clear()
mon.setCursorPos(1,1)
mon.write(" Tickets")
end
function newtitle()
mon.clear()
mon.setCursorPos(1,1)
mon.write(" Tickets")
term.clear()
term.setCursorPos(1,1)
print("+-----------------------------------------------+")
print("|  Welcome to Railnet Automated Ticket System   |")
print("+-----------------------------------------------+")
print("		  Please select destination")
end
function destinations()
term.setCursorPos(1,8)
print("1. Sandville")
print("2. Main Station")
term.setCursorPos(1,15)
write("Destination: ")
end
-- end screen functions
-- action functions
function pticket(name, w)
    rs.setOutput("back", true)
	 sleep(.5)
    rs.setOutput("back", false)
	 sleep(1)
    disk.setLabel("bottom", name)
    print("Thank you, your ticket will now print")
	 sleep(2)
    disk.eject("bottom")
    term.clear()
    term.setCursorPos(1,8)
    print("Your ticket has been printed.")
    print("Please redeem at next station")
	 sleep(2)
    os.reboot()
end
--end action functions
-- vars
mon = peripheral.wrap("top")
-- end vars
mon.setTextScale(2)
newtitle()
destinations()
while true do
  select = read()
  if select == "1" then
    pticket(Sandville)
  elseif select == "2" then
    pticket(Station)
  elseif disk.isPresent("bottom") == false then
    print("No tickets available. Please contact the Admin.")
	 sleep(2)
    os.reboot()
  else
    print("Invalid Destination. Please try again")
	 sleep(1)
    os.reboot()
  end
end
Edited on 29 July 2012 - 02:23 AM
Xenthera #7
Posted 29 July 2012 - 04:31 AM
Oh, that's an easy fix.

if select == "1" then
    pticket("Sandville")
  elseif select == "2" then
    pticket("Station")

Just put qoutes around sandville, and station, and it will pass a string to your print function. Instead of a nil.
Cranium #8
Posted 29 July 2012 - 04:33 AM
Oh wow, I can't believe I'm that stupid…. Yeah, I thought about that, but dismissed it thinking it wouldn't work. Thanks! I think I need some sleep…
Xenthera #9
Posted 29 July 2012 - 04:39 AM
You're welcome. Is this on a server? It seems like a cool system you have going, and I'd like to come check it out! If not it's okay though.
Cranium #10
Posted 29 July 2012 - 05:19 AM
Yeah, I do have it on a server, but I don't have a good enough internet connection to host outside of my house. When I get all my bugs worked out, I'll be happy to open it up to some people. Not too much, since I'm kind of a newbie when it comes to hosting. I also have several other programs like a master control system, a reactor control, and several other small projects I'm working on. When I do get them working, I'll post them in the Programs section.
Xenthera #11
Posted 29 July 2012 - 05:35 AM
I'm hosting a server right now as well. If you want add me on skype and I can send you the client for it. There is a total of 36 mods installed…

bobbylucero10