Jump to content




Elevator


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

#1 Livebait

  • Members
  • 7 posts

Posted 06 April 2013 - 11:22 AM

I made a little elevator using frame motors and wanted the up down feature to be controled by a computer. i have all the logic circuits set up and working i basically am needing a program that....
A: Sends a redstone signal to a remote computer (i put modems on both cause i think i had to)
B: perhaps since im using advanced computers if we could haev it setup to boot and have a little GUI with pretty much a floor selection (via button preferred not typing)
and C: if possible play elevator music :P

#2 QuantumGrav

  • Members
  • 36 posts
  • LocationUnited States

Posted 06 April 2013 - 12:09 PM

This is quite a big program, designing a nice looking GUI with mouse support that transmits the selection to another computer. I'd rather not just design one for you, since I don't know your particular setup and all that other jazz (and also because I'm slightly lazy and selfish with my time ;)), but I'll give you the resources to build your own. With a little effort, and some trial and error, I'm sure you can get it to work.

First, here is a short guide on menu making. These concepts can be used to help create your program.
http://www.computerc...gh-menu-making/

Second, to get mouse support, you'll need to learn how to use 'os.pullEvent()', one of the most useful commands in ComputerCraft.
http://www.computerc...1156#entry11156
Let's say you want a button that is the dead center of the screen. To use it, you'll use something like:
local w,h = term.getSize()  -- Gets the size of the screen and sets the variables w and h to it.
rednet.open("right") -- Opens the modem that you attached to the computer.  Change 'right' to whatever side the modem's on.

while true do  -- Repeat forever
  event, id, x, y = os.pullEvent()
  if event == "mouse_click" then -- If the mouse was clicked...
    if x == w/2 and y == h/2 then -- if the cursor was at the middle of the screen...
	  -- You've Succesfully hit that button!  Do stuff with it like:
	 rednet.broadcast("button_hit") -- Send out a message to another computer, for instance commanding it to start the elevator.
    end
  end
end
(Code not tested, but it should work.)

I'd also highly recommend checking out nitrogenfinger's youtube video on GUI's.


For the music playing, hook up a disk drive to your computer, put in a music disk, and tell it to play with 'disk.playAudio(string of drive's side)'.

It's a demanding project, and you might want to do something simpler if your not already pretty confident in Lua. That said, if you work through it, it's a fun and rewarding experience!

Hope that helps!

#3 Livebait

  • Members
  • 7 posts

Posted 06 April 2013 - 01:07 PM

theres too much to read through... how bout a more basic program... triggers redstone signal at another computer .... simple gui maybe 1 for first floor 2 for second floor :P

#4 QuantumGrav

  • Members
  • 36 posts
  • LocationUnited States

Posted 06 April 2013 - 04:11 PM

Sure! I would use something like this:

Spoiler

I was able to cut a few corners since you only wanted two options. Unfortunately, I don't have access to ComputerCraft right now, so I can't test this. Should work. The receiving computer should look like this:

Spoiler

Again, this is untested.

If you get any errors when running these programs, fix it yourself or let me know, I'd be glad to fix my mistake! This system is (probably) overloadable, so don't spam commands, or it might break. This is a pretty good base for the program, so feel free to edit and change to your heart's content!

Hope that helps!

#5 Livebait

  • Members
  • 7 posts

Posted 07 April 2013 - 11:40 AM

wow that code just looks amazing :P man if you typed all that kudos i appreciate the little bit of teaching done at the end . if you did it some other way thanks still. got 2nd computer all set up first is giving me an error at line 22 for end function somethin?

#6 SadKingBilly

  • Members
  • 160 posts

Posted 07 April 2013 - 02:35 PM

View PostLivebait, on 07 April 2013 - 11:40 AM, said:

wow that code just looks amazing :P man if you typed all that kudos i appreciate the little bit of teaching done at the end . if you did it some other way thanks still. got 2nd computer all set up first is giving me an error at line 22 for end function somethin?
If you just copied his code, then I'm pretty sure the problem is the second 'do' on the line "while true do do -- Repeat forever".

#7 Livebait

  • Members
  • 7 posts

Posted 07 April 2013 - 03:06 PM

hmm that fixxed that... now getting -- "Elevator:4: attempt to call nil -- hate to keep asking for help but this stuff might as well be.... well id say a different language but technically it is :P heh either way i cant do much i fixxed some bugs i had myself from copying it but when the code itself seems to have an error i cant even come up with a half brained idea of what to do

#8 Livebait

  • Members
  • 7 posts

Posted 07 April 2013 - 03:19 PM

im not sure what nil is only in lines 24/46 and the one result says its to reset it seems pretty basic... im guessing its the line 46? should i break that up or ?

#9 Livebait

  • Members
  • 7 posts

Posted 07 April 2013 - 03:28 PM

ok playing around with it i think imnot supposed to copy it verbatim on line 46 the tostring is where i put the computer im sending the signal to? least thats what my head is coming up with

#10 Livebait

  • Members
  • 7 posts

Posted 07 April 2013 - 04:17 PM

ok no ill give up and wait for next advice :P

#11 SadKingBilly

  • Members
  • 160 posts

Posted 07 April 2013 - 04:26 PM

As far as I can tell, the only thing that would prevent QuantumGrav's code from executing at all is the duplicate "do" that I mentioned. Otherwise, you may have just copied it incorrectly.

Honestly, it would be far easier to just use a command-line interface:
-- Elevator interface
rednet.open("right")
while true do
	term.clear()
	term.setCursorPos(1, 1)
	print("What floor would you like to go to?")
	selection = read()
	if tonumber(selection) == 1 then
		rednet.broadcast("1")
	elseif tonumber(selection) == 2 then
		rednet.broadcast("2")
	else
		print("Floor not valid.")
		os.sleep(3)
	end
end
-- Elevator controller
rednet.open("right")
while true do
	_, message = rednet.receive()
	if tonumber(message) == 1 then
		-- floor 1 code goes here
	elseif tonumber(message) == 2 then
		-- floor 2 code goes here
	end
end


#12 QuantumGrav

  • Members
  • 36 posts
  • LocationUnited States

Posted 07 April 2013 - 05:16 PM

Sorry about the extra 'do' in the code! Stuff like that happens when you code that much and can't test.

I double checked my code, and I can't see why it's not working for you. I would double check in both codes that the "right" in rednet.open("right") is changed to whatever side your modem is on. The sides that you can change it to are: top, bottom, left, right, front, and back. If that's all good, I'm not sure what's causing your error!

TheCoryKid is right, something like he has made would be simpler, so use that if you'd prefer! I hope you can get your Elevator working!


#13 theoctagon

  • Members
  • 15 posts

Posted 10 April 2013 - 08:54 AM

I can actually help with this. I wrote a VERY basic elevator program that I'll share. It is set as the startup for each adv. comp on each floor. Each floor has the blocks above and below the floor/ceiling as blocks that are pushed out to stop the traveler at the floor requested. Obviously its set up for my particular situation and mechanics, but perhaps some of the coding will help you figure it out a little easier.

Enjoy!

flr = 0
curflr = 3
outputside = "back"
modemside = "bottom"
chk = false
comp1 = 131
comp2 = 127
comp3 = 128
comp4 = 130
comp5 = 133
comp6 = 137
comp7 = 139
comp8 = 142
comp9 = 144
comp10 = 146

local self = os.getComputerID()

function chgflr(flr,chk)
-- chk is for ensuring activation
print(flr," = floor passed")
if flr == 1 then
flr = tonumber(comp1)
elseif flr == 2 then
flr = tonumber(comp2)
elseif flr == 3 then
flr = tonumber(comp3)
elseif flr == 4 then
flr = tonumber(comp4)
elseif flr == 5 then
flr = tonumber(comp5)
elseif flr == 6 then
flr = tonumber(comp6)
elseif flr == 7 then
flr = tonumber(comp7)
elseif flr == 8 then
flr = tonumber(comp8)
elseif flr == 9 then
flr = tonumber(comp9)
elseif flr == 10 then
flr = tonumber(comp10)
end
-- print("Passed the if's")
rednet.send(flr,"Activate")
print("Message sent to the ", flr, " floor")
-- print("You have 10 seconds to arrive.")
os.sleep(300)
term.clear()
end

function scrnmsg(flr)
term.clear()
term.setCursorPos(1,1)
print("Hello, I am ", self)
print("Please select floor: ")
print("1: Bridge ")
print("2: Bridge - Lower level")
print("3: 10 - forward")
print("4: Transporters")
print("5: Sick Bay")
--print("6: Engineering")
--print("7: Empty Deck")
--print("8: Crew Deck")
--print("9: Biosphere")
print(" ")
flr = read()

flr = tonumber(flr)
print()
print("You've selected: ", flr)

if flr == curflr then
print("Same floor")
flr = 0
return
end
if flr <= curflr then
dir = "up"
if flr <= 1 then
flr = 1
else
flr = flr -1
end

print(flr, "Floor")
end
-- print("Flooring")
-- print(flr)
chgflr(flr)
-- print("back")

return
end

function listen(sender, message)
rednet.open(modemside)
sender, message = rednet.receive()
print("Sender: ", sender, " Sent the following message: ",message)
if message == "Activate" then
rs.setOutput(outputside, true)
os.sleep(5)
rs.setOutput(outputside, false)
end

return sender, message
end

--- Begin program run
while true do
term.clear()
print("Starting .....")
parallel.waitForAny(scrnmsg, listen)
-- print("next ...")
-- print(flr)
-- print("Done")
end

#14 Smiley43210

  • Members
  • 204 posts

Posted 10 April 2013 - 09:24 AM

I've actually started working on an elevator script a month or two ago, so if I'm feeling helpful soon, I might post bits of it to help, the GUI creation in particular (auto generates according to monitor size, has a configureable "floor list" table that you put your floor names and such in).

#15 theoctagon

  • Members
  • 15 posts

Posted 10 April 2013 - 09:41 AM

View PostSmiley43210, on 10 April 2013 - 09:24 AM, said:

I've actually started working on an elevator script a month or two ago, so if I'm feeling helpful soon, I might post bits of it to help, the GUI creation in particular (auto generates according to monitor size, has a configureable "floor list" table that you put your floor names and such in).

Sounds awesome!

#16 Smiley43210

  • Members
  • 204 posts

Posted 10 April 2013 - 06:19 PM

Yea, this is going to lead to spoon feeding...

But how do you want it to look?
Something like this?
http://imgur.com/QOppk9N
http://imgur.com/AtdzdEt

#17 QuantumGrav

  • Members
  • 36 posts
  • LocationUnited States

Posted 11 April 2013 - 05:08 AM

@theoctagon: I really recommend putting code that large into a code and a spoiler, it's just nicer for others to read that way.

@Smiley43210: I'd also enjoy seeing that program! Sounds neat.

@Livebait: Have you gotten any of these programs to work how you want them to yet?

#18 Smiley43210

  • Members
  • 204 posts

Posted 13 April 2013 - 12:32 PM

Ok, I'll post it when school is over.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users