Jump to content




LUA Menu sample


  • You cannot reply to this topic
14 replies to this topic

#1 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 26 April 2015 - 03: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


#2 Square789

  • Members
  • 39 posts
  • LocationUniverse:C:/MilkyWay/Sol/Earth/Europe/Germany

Posted 26 April 2015 - 04: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()

#3 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 26 April 2015 - 05: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.

#4 Cing

  • Members
  • 72 posts

Posted 26 April 2015 - 05:55 PM

I think you want to use monitor and make a simple button program.
Use this api http://www.computerc..._hl__touchpoint

#5 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 26 April 2015 - 05: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 by HPWebcamAble, 26 April 2015 - 05:57 PM.


#6 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 26 April 2015 - 08: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

#7 Cing

  • Members
  • 72 posts

Posted 26 April 2015 - 08: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.

#8 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 26 April 2015 - 09: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.

#9 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 26 April 2015 - 10: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 by Dragon53535, 26 April 2015 - 10:29 PM.


#10 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 27 April 2015 - 02: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.

#11 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 27 April 2015 - 03: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 by Dragon53535, 27 April 2015 - 03:29 AM.


#12 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 27 April 2015 - 08: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.

#13 Cing

  • Members
  • 72 posts

Posted 27 April 2015 - 10:16 AM

I you want more dan one thing happend when you touch you button, then you make a function for the button.

View PostDragon53535, on 26 April 2015 - 10:28 PM, said:

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.../Redstone_(API)

Edited by Cing, 27 April 2015 - 10:21 AM.


#14 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 27 April 2015 - 10:13 PM

View PostCing, on 27 April 2015 - 10:16 AM, said:

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 by Dragon53535, 27 April 2015 - 10:13 PM.


#15 iceman11a

  • Members
  • 68 posts
  • LocationUSA

Posted 28 April 2015 - 12:44 AM

Thank you very much, That works.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users