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

Touch Ticket System

Started by TUSgvi1, 16 September 2014 - 10:05 AM
TUSgvi1 #1
Posted 16 September 2014 - 12:05 PM
Hello Guys,
at first i apologize me for my bad English.
I'm a PHP IT Student so i can Programming some awesome Stuff but now i need help in lua.
i got very angry Yesterday because of my Computercraft Ticket system.

I want the following :

There are 2 Options where you can go : Neuss and Duesseldorf.

I want that you can press the destination with the right mouse button and you have to take into a chest 2 gold bares. after this an item detector take a redstone signal out an the ticket will be printed.

that's the idea.

So this is my script until now. My Problem is that if i click on the monitor the ticket will imidently printed.

maybe you have some ideas?


shell.run("clear")
local mon = peripheral.wrap('monitor_3')
local station1 = "Neuss"
local station2 = "Duesseldorf"
local p = peripheral.wrap("back")
local choice = 0
function Rahmen()
term.setBackgroundColor(colors.blue)
term.setCursorPos(1,4)
mon.write ("Wohin solls gehen?")
term.setCursorPos(2,6)
mon.write ("Neuss")
term.setCursorPos(3,8)
mon.write("Duesseldorf")
end
function eingabe ()
	while choice < 1 do
	event,side,x,y =os.pullEvent()
if event == "monitor_touch" then
	
		if x == 1 and y == 6 then
	 term.clear()
  term.setCursorPos(1,1)
  choice = choice + 1
  mon.write("Bitte 2 Gold einwerfen")
			while true do
			os.pullEvent("redstone")
				if rs.getInput("right") then
			 break
	end
		 end
	 end
  term.clear()
		p.createTicket (station1)
	 mon.write ("Vielen Dank")
  sleep(5)
  term.clear()
end

	if x == 1 and y == 8 then
choice = choice + 1
mon.write("Bitte 2 Gold einwerfen")
		while true do
		os.pullEvent("redstone")
			if rs.getInput("right") then
		 break
		 end
	 end
		term.clear()
		p.createTicket (station2)
	 mon.write ("Vielen Dank")
  sleep (5)
  term.clear()
	end
end
end
if choice == 1 then
choice = 0
end

while true do
Rahmen()
eingabe()
end
Edited on 16 September 2014 - 12:27 PM
Saldor010 #2
Posted 16 September 2014 - 02:51 PM
Your code looks fine… Are you sure there may not be a problem with the item detector setup? If possible, could you give us a screenshot of the setup?
TUSgvi1 #3
Posted 16 September 2014 - 03:09 PM
Here some Screens from the mechanic.

This is the backside

There is an Itemloader and an Itemdeloader. The Itemloader load the 2 gold bares into the chestcart and the itemdetector (Railcraft) detect the 2 gold bares. then he put a redstone signal out to the computer and the item loader to the rail. the item deloader deload the gold bares an now i habe a endless rythm.My Problem is not the Manual machine The Script seems the fail.
Here a foto from the Monitor :

Its not Formated how i tiped it into the listing (do it call listing in lua?)
anything is in the same line and unclickable.

I dont now whats wrong.

if you want to take a look onto my Mechaniks its Techworld 2 with traincraft, its a serer and i have a Teamspeak.
also i can you only take screens.
Bomb Bloke #4
Posted 16 September 2014 - 03:25 PM
The issue is indeed in the code.

First, here's a version with no changes other than fixed indentation:

Spoiler
shell.run("clear")
local mon = peripheral.wrap('monitor_3')
local station1 = "Neuss"
local station2 = "Duesseldorf"
local p = peripheral.wrap("back")
local choice = 0

function Rahmen()
	term.setBackgroundColor(colors.blue)
	term.setCursorPos(1,4)
	mon.write ("Wohin solls gehen?")
	term.setCursorPos(2,6)
	mon.write ("Neuss")
	term.setCursorPos(3,8)
	mon.write("Duesseldorf")
end

function eingabe ()
	while choice < 1 do
		event,side,x,y =os.pullEvent()
		if event == "monitor_touch" then

			if x == 1 and y == 6 then
				term.clear()
				term.setCursorPos(1,1)
				choice = choice + 1
				mon.write("Bitte 2 Gold einwerfen")
				while true do
					os.pullEvent("redstone")
					if rs.getInput("right") then
						break
					end
				end
			end
			term.clear()
			p.createTicket (station1)
			mon.write ("Vielen Dank")
			sleep(5)
			term.clear()
		end

		if x == 1 and y == 8 then
			choice = choice + 1
			mon.write("Bitte 2 Gold einwerfen")
			while true do
				os.pullEvent("redstone")
				if rs.getInput("right") then
					break
				end
			end
			term.clear()
			p.createTicket (station2)
			mon.write ("Vielen Dank")
			sleep (5)
			term.clear()
		end
	end
end

if choice == 1 then
	choice = 0
end

while true do
	Rahmen()
	eingabe()
end

That should make it a lot easier to see where your problem is: Because of a misplaced "end", "p.createTicket (station1)" is sitting in the "if event == "monitor_touch" then" block. It fires every time that block runs, regardless as to where the mouse click was performed.

By the way, this:

				while true do
					os.pullEvent("redstone")
					if rs.getInput("right") then
						break
					end
				end

… could be re-written as just this:

				repeat os.pullEvent("redstone") until rs.getInput("right")
TUSgvi1 #5
Posted 16 September 2014 - 03:36 PM
I don't understand enoug to make the code really new. the part with the new redstone event I Understand, but i don't know what you want from the If "boxes" should i try to take the ticket machine an end before?
Bomb Bloke #6
Posted 16 September 2014 - 04:01 PM
Move the "ends" like this:

Spoiler
shell.run("clear")
local mon = peripheral.wrap('monitor_3')
local station1 = "Neuss"
local station2 = "Duesseldorf"
local p = peripheral.wrap("back")
local choice = 0

function Rahmen()
	term.setBackgroundColor(colors.blue)
	term.setCursorPos(1,4)
	mon.write ("Wohin solls gehen?")
	term.setCursorPos(2,6)
	mon.write ("Neuss")
	term.setCursorPos(3,8)
	mon.write("Duesseldorf")
end

function eingabe ()
	while choice < 1 do
		event,side,x,y =os.pullEvent()
		if event == "monitor_touch" then

			if x == 1 and y == 6 then
				term.clear()
				term.setCursorPos(1,1)
				choice = choice + 1
				mon.write("Bitte 2 Gold einwerfen")
				while true do
					os.pullEvent("redstone")
					if rs.getInput("right") then
						break
					end
				end
				term.clear()
				p.createTicket (station1)
				mon.write ("Vielen Dank")
				sleep(5)
				term.clear()
			end


			if x == 1 and y == 8 then
				choice = choice + 1
				mon.write("Bitte 2 Gold einwerfen")
				while true do
					os.pullEvent("redstone")
					if rs.getInput("right") then
						break
					end
				end
				term.clear()
				p.createTicket (station2)
				mon.write ("Vielen Dank")
				sleep (5)
				term.clear()
			end
		end
	end
end

if choice == 1 then
	choice = 0
end

while true do
	Rahmen()
	eingabe()
end
TUSgvi1 #7
Posted 16 September 2014 - 04:10 PM
Ok. I edited Anything. Now my Program will not Start. Any functions and if clauses are closed

do you have any idea?


local mon = peripheral.wrap('monitor_3') -- Conectet via Network-Cable
local station1 = "Neuss"
local station2 = "Duesseldorf"
local p = peripheral.wrap("back")
local choice = 0
function Rahmen()
mon.setBackgroundColor(colors.blue)
mon.setCursorPos(1,1)
mon.write ("Wohin solls gehen?")
mon.setCursorPos(1,3)
mon.write ("Neuss")
mon.setCursorPos(1,5)
mon.write("Duesseldorf")
eingabe()
end
function eingabe ()
	while choice < 1 do
	event,side,x,y = os.pullEvent()
if event == "monitor_touch" then
	
		if x >= 1 and x <= 5 and y == 3 then
	 mon.clear()
  mon.setCursorPos(1,1)
  choice = choice + 1
  mon.setCursorPos(1,1)
  mon.write("Bitte 2 Gold einwerfen")
		repeat os.pullEvent("redstone") until rs.getInput("right")
		  mon.clear()
		p.createTicket (station1)
  mon.setCursorPos(1,1)
	 mon.write ("Vielen Dank")
  sleep(5)
  mon.clear()
  choice = 0
  end



	if x >= 1 and x <= 11 and y == 5 then
choice = choice + 1
  mon.clear()
mon.setCursorPos(1,1)
mon.write("Bitte 2 Gold einwerfen")
	repeat os.pullEvent("redstone") until rs.getInput("right")
	 mon.clear()
		p.createTicket (station2)
  mon.setCursorPos(1,1)
	 mon.write ("Vielen Dank")
  sleep (5)
  mon.clear()
  choice = 0
  end
	end
end
end
Edited on 16 September 2014 - 04:35 PM
Saldor010 #8
Posted 16 September 2014 - 07:09 PM
I see no where in the new code that you are calling the function "Rahmen", which appears to be where your code is supposed to start. Try calling it at the bottom of your code and see if that works.
TUSgvi1 #9
Posted 16 September 2014 - 07:20 PM
I try to take it at the button but now i can get one ticket, after that i want that my code return to the start. but i only get a "Bluescreen" hahaha
There no Words where i can click

Saldor010 #10
Posted 16 September 2014 - 08:02 PM
Try putting "Rahmen" in a while true do loop at the end of your program like so,


...
while true do
  Rahmen()
end

That should keep calling your "main" function until the computer turns off or the program is terminated.
TUSgvi1 #11
Posted 16 September 2014 - 08:56 PM
The Bluescreen is also there…

Edit : it was my fail, sorry about thar
Edited on 16 September 2014 - 07:35 PM
Bomb Bloke #12
Posted 17 September 2014 - 02:36 AM
Dunno if you worked it out, but you never reset "choice" back to 0.
TUSgvi1 #13
Posted 17 September 2014 - 08:26 AM
Yeah i put it before the while loop but after the function "eingabe" so now it will reset. anything is fine :)/>

Here's the code for someone who is interessted in a good ticket system
http://pastebin.com/fXVS1nTn
TUSgvi1 #14
Posted 18 September 2014 - 02:36 PM
Sorry For open a "Closed" Topic. I get a Problem. I tried to make a abort button.
But It doesnt Abort, do you maybe have some ideas?


local mon = peripheral.wrap('monitor_13') -- Conectet via Network-Cable
local station1 = "Duesseldorf"
local station2 = "Grevenbroich"
local station3 = "Grand Central St."
local p = peripheral.wrap("back")
local choice = 0
rs.setOutput("right", true)
function rahmen()
mon.clear()
mon.setBackgroundColor(colors.blue)
mon.setCursorPos(1,1)
mon.write ("Wohin solls gehen?")
mon.setCursorPos(1,3)
mon.write ("Duesseldorf")
mon.setCursorPos(1,5)
mon.write("Grevenbroich")
mon.setCursorPos(1,7)
mon.write("Grand Central St.")
eingabe()
end
function eingabe ()
    while choice < 1 do
    event,side,x,y = os.pullEvent()
if event == "monitor_touch" then
	 
	    if x >= 1 and x <= 11 and y == 3 then
	 mon.clear()
  mon.setCursorPos(1,1)
  choice = choice + 1
  mon.setCursorPos(1,1)
  mon.write("Bitte 2 Gold einwerfen")
  mon.setCursorPos(1,5)
	    mon.write("Abort") <- Here will be write Abort
  if x >= 1 and x <= 10 and y == 5 then <--- If he click thhere it will break.
  break
  else
  rs.setOutput("right", false)
	    repeat os.pullEvent("redstone") until rs.getInput("front")
  rs.setOutput("right", true)
	 mon.clear()
	    p.createTicket (station1)
  mon.setCursorPos(1,1)
	 mon.write ("Vielen Dank")
  sleep(12)
  mon.clear()
  end
  end
 

 
    if x >= 1 and x <= 12 and y == 5 then
choice = choice + 1
  mon.clear()
mon.setCursorPos(1,1)
mon.write("Bitte 2 Gold einwerfen")
rs.setOutput("right", false)
    repeat os.pullEvent("redstone") until rs.getInput("front")
rs.setOutput("right", true)
	 mon.clear()
	    p.createTicket (station2)
  mon.setCursorPos(1,1)
	 mon.write ("Vielen Dank")
  sleep (12)
  mon.clear()
  end
 
  if x >= 1 and x <= 17 and y == 7 then
choice = choice + 1
  mon.clear()
mon.setCursorPos(1,1)
mon.write("Bitte 2 Gold einwerfen")
rs.setOutput("right", false)
    repeat os.pullEvent("redstone") until rs.getInput("front")
rs.setOutput("right", true)
	 mon.clear()
	    p.createTicket (station3)
  mon.setCursorPos(1,1)
	 mon.write ("Vielen Dank")
  sleep (12)
  mon.clear()
  end
    end
end
choice = 0
end
while true do
  rahmen()
end

Saldor010 #15
Posted 18 September 2014 - 02:43 PM
Your problem is, you're checking if the person clicked the "Abort" button only once, at the front of the code. If he didn't, then it continues to the code where it waits for him to drop in the gold, and it never looks at the abort button again. One easy fix, would be to remove the abort button, and place an actual stone button next to the monitor, that leads redstone to the computer. Then you could do something like this.


...
repeat os.pullEvent("redstone") until rs.getInput("front") or rs.getInput(side where button is)
if rs.getInput(side where button is) then
  break
end
...
TUSgvi1 #16
Posted 18 September 2014 - 08:50 PM
Thats a great Idea, but is there no Graphic Possibility?
Saldor010 #17
Posted 21 September 2014 - 02:22 AM
Thats a great Idea, but is there no Graphic Possibility?

Not in the solution I gave, no. But I just gave you the simplest solution (In my opinion). You can still do it graphically, it would just be a bit more complex.