Jump to content




Help with elevator program


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

#1 djfergy

  • Members
  • 3 posts

Posted 30 June 2016 - 09:52 PM

So i am creating a 2 part elevator program using frames that works but not the way i want it to. The way is it supposed to work is that when i hit the call button from a floor it should go straight to that floor in which the call button was pushed. Instead it stops at each floor. I do know that the problem is the while statement but for the life of me i cannot firgure out how to isolate each of the functions. The green wire is for going up and the rred wire is for going down. All of the other wires are just inputs and sensors.
local side = "left"
function flr1()
  if redstone.testBundledInput(side,colors.black) == true then
    redstone.setBundledOutput(side,colors.red)
    sleep(3)
  end
  if redstone.testBundledInput(side,colors.white) == true then
    redstone.setBundledOutput(side,0)
  end
  --sleep(.1)
end
function flr2()
  if redstone.testBundledInput(side,colors.gray) == true and
  redstone.testBundledInput(side,colors.white) == true then
    redstone.setBundledOutput(side,colors.green)
    sleep(3)
  end
 
  if redstone.testBundledInput(side,colors.gray) == true and
  redstone.testBundledInput(side,colors.cyan) == true then
    redstone.setBundledOutput(side,colors.red)
    sleep(3)
  end
 
  if redstone.testBundledInput(side,colors.lightGray) == true then
    redstone.setBundledOutput(side,0)
  end
  --sleep(1)
end
function flr3()
  if redstone.testBundledInput(side,colors.blue) == true then
    redstone.setBundledOutput(side,colors.green)
    sleep(3)
  end
 
  if redstone.testBundledInput(side,colors.cyan) == true then
    redstone.setBundledOutput(side,0)
  end
  --sleep(.1)
end
while true do
  flr1()
  flr2()
  flr3()
  sleep(.1)
end


#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 01 July 2016 - 08:03 AM

It stops at each floor because your program doesn't wait until the elevator gets to where it should be, it instead just waits for 3 seconds after asserting either the green or the red wire and after it, it goes back into the infinite loop.

I suggest two changes:
  • Make it all event driven: don't poll the input, wait for "redstone" events instead
  • Use tables: store the floors and relevant data in tables, iterate those tables when a redstone event occurs
This is the code I had in mind

Code works and is tested. It should give you an idea of how I think it should work.

How do the green and red wires work though? Does the elevator just move by itself when they are asserted? Is there a circuit generating the pulses needed by the frame motors? I assumed there is one, so the above code does too.

Edited by LBPHacker, 01 July 2016 - 08:07 AM.


#3 djfergy

  • Members
  • 3 posts

Posted 01 July 2016 - 11:03 AM

Spoiler
it's just a tad overcomplicated frame elevator lol. yes they use timers. i'll give your code a shot tomorrrow. thanks a bunch!

#4 djfergy

  • Members
  • 3 posts

Posted 20 July 2016 - 02:51 AM

Apologies for double post. I need help again! So the call program works great but that was only half of elevator programming. The second half is a button monitor that allows you to select which floor to go to and then takes you there. I have an example of the monitor below.
Spoiler
In my test world, I only have 3 levels currently built. There are six floors just to test the size and spacing. I am using a modified version of direwolf20's button api to make the buttons function correctly. Now I just need to make the elevator move correctly. This is what I have so far.
Spoiler
and for reference here is the button api
Spoiler
Do I need to use table again? I'm not very familiar with how they work at all....





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users