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

LUA Menu sample

Started by iceman11a, 26 April 2015 - 02:57 PM
iceman11a #1
Posted 26 April 2015 - 04:57 PM
What's I'm tring to do is run a lua code to creat tickets using the ticket machine from openmods. I have some code and sense I really don't get into lua code all that much. I thought I would ask for some help.


What I need to do is take this code I have and make a menu for it to display places to go and when a numbers is selected a tcket is created. The code below is what I wanted to use. I just don't know what the rednet is for. Can some one help with a menu for this code.



local TM = peripheral.wrap("top")
rednet.open("bottom")
function sea()
local booleanInfo = TM.createTicket("South/SeaStation")
end
function lake()
local booleanInfo = TM.createTicket("North/Lake")
end
while true do
eventType, sender, message, dist = os.pullEvent("rednet_message")
if message == "sea" then
  sea()
elseif message == "lake" then
  lake()
else
  print("invalid message")
end
end
Square789 #2
Posted 26 April 2015 - 05:43 PM
You are using rednet for target selection, which means that you would have to set up another computer, connect it via modems and so on…

Instead of

eventType, sender, message, dist = os.pullEvent("rednet_message")
I'd use this:
local message = read()
iceman11a #3
Posted 26 April 2015 - 06:24 PM
Thanks for the info. I just don't know how to use rednet. My idea was just to get a menu setup so that player could select from that menu and that ticket they could use it in a train to take with where ever they wanted to go. As for redned. I don't know what that would be for. I fount this code off another same world for single players, I couldn't load the world in because of some missing mods. the world just crash on me. So I couldn't get in to see how it all works.

All I want it a menu to select tickets and have it use a ticket machine to give the user a ticket.
Cing #4
Posted 26 April 2015 - 06:55 PM
I think you want to use monitor and make a simple button program.
Use this api http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/page__hl__touchpoint
HPWebcamAble #5
Posted 26 April 2015 - 06:57 PM
You'll probably want to use an API to create buttons

My Screen API would work:
http://www.computerc...061-screen-api/


You could try using my Simple Screen Maker (In my signature) but it might be a bit difficult to use at the moment, I'm updating it to make it better


If you need help with my API, or any others that you find, feel free to ask


Edit: Ninja'd
Edited on 26 April 2015 - 04:57 PM
iceman11a #6
Posted 26 April 2015 - 09:06 PM
I'm sorry, This is very confusing, Let me see if I have this right. This is some kind of a API that lets me create buttons on the monitor of a PC from computercraft. It lets me click on a button and then I can do all most any thing. Now here's the hard part. How would I use this with a ticket machine.

I want so many buttons to make so many tickets using the ticket machine.

Location
-Nimrod Nimrod/pass
-Citysky Citysky/pass
-Mainbase Mainbase/pass
-City City/pass
-Station 1 Station1/pass
Cing #7
Posted 26 April 2015 - 09:55 PM
just make a button for each location.
And have a function to each button that makes the ticket.
I don't know how many locations you have but you can make a monitor pretty big.
iceman11a #8
Posted 26 April 2015 - 10:43 PM
Sorry,. This doesn't seem to work. I'm not doing some ting right or I have no idea what to do. I'll have to come up with another idea on how to do some thing. The thing is that I don't know what I'm doing. This is why I wanted to stay a way from lua code.

I click on the button and nothing happens. and the 2nd button doesn't show. I need these buttons to show on the big monitor. Not just the little pc.
Dragon53535 #9
Posted 26 April 2015 - 11:28 PM
Use the touchpoint api already linked into the topic. Lets say you're having two buttons, one for North, the other for South. You'd set that up like this:


local tm = peripheral.wrap("top") --#The ticket machine
local t = touchpoint.new("right") --#Right being where the monitor is, change if needed
t:add("North",function() tm.createTicket("North") end,1,1,15,3,colors.red,colors.lime) --#Creating a north button with x1 at 1, y1 at 1, and x2 at 15 and y2 at 3. The button will be green.
t:add("South",function() tm.createTicket("South") end,1,5,15,8,colors.red,colors.lime) --#Same thing, just down a couple lines.
t:run()
This should just print out a ticket any time either button is pressed.


MAKE SURE THE TOUCHPOINT API IS ON THE COMPUTER
Edited on 26 April 2015 - 09:29 PM
iceman11a #10
Posted 27 April 2015 - 03:43 AM
Thank you very much. That code works. Now do I add my own lines to this code. Lets say I wanted to turn a signal from a bundle cable, or some thing.

The idea is to add more lines to each button click. And last. I need to be able to add 5 buttons. How can I make the buttons smaller.
Dragon53535 #11
Posted 27 April 2015 - 04:07 AM
Change the difference between x1 and x2, and y1 and y2.

t:add("blah",function() print("blah") end, 1,1,5,5,colors.red,colors.lime)
t:add("blah",function() print("blah") end, 1,1,10,10,colors.red,colors.lime)
the bottom one is double the size of the top one.

To clarify, first 2 numbers say the top left corner, the second two say the bottom right corner
Edited on 27 April 2015 - 02:29 AM
iceman11a #12
Posted 27 April 2015 - 09:57 AM
That means then trial and error. I won't know just what to set those numbers too. Now. How can I add my own lines of code to this code. Lets say I wanted to send a red stone signal threw a bundled cable.
Cing #13
Posted 27 April 2015 - 11:16 AM
I you want more dan one thing happend when you touch you button, then you make a function for the button.


local tm = peripheral.wrap("top") --#The ticket machine
local t = touchpoint.new("right") --#Right being where the monitor is, change if needed
t:add("North", North,1,1,15,3,colors.red,colors.lime) --#Creating a north button with x1 at 1, y1 at 1, and x2 at 15 and y2 at 3. The button will be green.
t:add("South", South,1,5,15,8,colors.red,colors.lime) --#Same thing, just down a couple lines.
t:run()

Use the same code but swap out "function() tm.createTicket() end" for North.
And then make a function for North.


function North()
	 tm.createticket("North")  --#Makes the ticket
	 redstone.setBundledOuput("right", colors.blue) --#Sets from the bundled cable right of the computer the color blue on.
	 --# You can have hear as many lines if you want.
end

EDIT: Go here for more information about redstone http://computercraft.info/wiki/Redstone_(API)
Edited on 27 April 2015 - 09:21 AM
Dragon53535 #14
Posted 27 April 2015 - 11:13 PM
I you want more dan one thing happend when you touch you button, then you make a function for the button.
Use the same code but swap out "function() tm.createTicket() end" for North.
And then make a function for North.


function North()
	 tm.createticket("North")  --#Makes the ticket
	 redstone.setBundledOuput("right", colors.blue) --#Sets from the bundled cable right of the computer the color blue on.
	 --# You can have hear as many lines if you want.
end

EDIT: Go here for more information about redstone http://computercraft.../Redstone_(API)
While correct, he doesn't exactly have to do that there, he can just add what he wants inside the function() end area.

t:add("South",function() tm.createTicket("South") rs.setBundledOutput("right",colors.lime) end,1,5,15,8,colors.red,colors.lime)
Edited on 27 April 2015 - 09:13 PM
iceman11a #15
Posted 28 April 2015 - 01:44 AM
Thank you very much, That works.