Jump to content




Need some help with Redstone inputs please :)

api lua help

23 replies to this topic

#1 Bmasta8899

  • New Members
  • 16 posts

Posted 23 July 2012 - 10:07 PM

Hey Guys I am attempting to create a door that flush with the wall in my room, i can open it useing the command on the console its self but im having trouble getting it to open a from the inside when i press the button


shell.run("clear")
print("Window's 7")
print("Piratebay edition")
print()
print("What would you like to do ben?")

input = read()

sc = "oldpeopleburning"

if input == sc then
print("Opening Private safe...")
sleep (1.0)
rs.setBundledOutput("bottom", colors.magenta)
sleep(0.5)
rs.setBundledOutput("bottom", colors.white)
sleep(10.0)
rs.setBundledOutput("bottom", colors.orange)
sleep(0.5)
rs.setBundledOutput("bottom", colors.black)
end

if rs.testInput("back") == true then
print("Opening Private safe...")
sleep (1.0)
rs.setBundledOutput("bottom", colors.magenta)
sleep(0.5)
rs.setBundledOutput("bottom", colors.white)
sleep(10.0)
rs.setBundledOutput("bottom", colors.orange)
sleep(0.5)
rs.setBundledOutput("bottom", colors.black)
end

shell.run("startup")


(Im useing RS latches and wireless RS to apply power to the door at the time it needs is)

#2 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 02:38 AM

Bump really need a hand, please help if u can

#3 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 24 July 2012 - 02:42 AM

1: For that empty print make it print(" ")
2: What is your error? - IF there is one.

#4 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 06:20 AM

Thank you for replying, even tho i press the button it wont run though the function

#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 July 2012 - 06:28 AM

you are calling the read() function, the program then stops and waits for you to enter your password so it won't check the back for redstone input until you have entered a password

#6 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 06:30 AM

ohhhhh ok, How would i fix that? Put the input before the read() function?

#7 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 24 July 2012 - 06:36 AM

View PostBmasta8899, on 24 July 2012 - 06:30 AM, said:

ohhhhh ok, How would i fix that? Put the input before the read() function?

Make the whole thing a function, I didin't proof read your code but just add
at the top:
function read()
--then at the bottom add
end
read()

#8 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 07:41 AM

You lost me a bit, i added that but still nothing....

#9 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 24 July 2012 - 07:44 AM

View PostBmasta8899, on 24 July 2012 - 07:41 AM, said:

You lost me a bit, i added that but still nothing....

Ugh let me space out your code and proof read it, I'll try to hand you a fix.

Also question, why are you shell running startup at the end of the code?

#10 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 July 2012 - 07:48 AM

neither of those options will work, you will either have to have 2 separate computers, one for password input and one to listen for redstone input or develop a new read function that pulls events to get your key presses for a password and simultaneously checks for a redstone event, sorry but that's the only way to get this working

#11 Darky_Alan

  • Members
  • 89 posts
  • LocationPuerto Rico

Posted 24 July 2012 - 08:05 AM

View PostKaoS, on 24 July 2012 - 07:48 AM, said:

neither of those options will work, you will either have to have 2 separate computers, one for password input and one to listen for redstone input or develop a new read function that pulls events to get your key presses for a password and simultaneously checks for a redstone event, sorry but that's the only way to get this working
Right, you can't have more than one loop running at a time.

#12 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 24 July 2012 - 08:09 AM

Yes you can.. Parallel api.
Tutorial

#13 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 09:09 AM

How would i implement that? haha once again sorry, Im new, this was like my 3rd attempt at writing a program haha

#14 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 09:11 AM

and im running startup at the end beacuse that's the name of the file and it restarts the programs after i A: type in a password or B: (hopefully haha) run the if statment with the Rs input

#15 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 24 July 2012 - 09:12 AM

Make 2 functions
add While true loop at the end.
function input()
   -- Input (read) sht here --
end
function rs()
   -- Redstone if's here --
end
while true do
   parallel.waitForAny(input, rs)
end

EDIT: 400th post.

#16 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 09:15 AM

Gottcha ill go try that, Gratz on the 400th post

#17 Bmasta8899

  • New Members
  • 16 posts

Posted 24 July 2012 - 09:27 AM

Attached Image: Untitled.jpgHere Is what i got

#18 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 July 2012 - 09:28 AM

still won't work... parallel api is complicated, I don't understand it fully but it will wait for the read() function to close

#19 BigSHinyToys

  • Members
  • 1,001 posts

Posted 24 July 2012 - 09:38 AM

View PostKaoS, on 24 July 2012 - 09:28 AM, said:

still won't work... parallel api is complicated, I don't understand it fully but it will wait for the read() function to close
just because something is complicated doesn't mean it wont work.
it is plausible to make two separate loops (coroutine) run at the same time(well a microsecond gap)
look at my program here specifically the WIFI section
http://www.computerc...esting-utility/
it is running a read while listening for rednet messages.

#20 BigSHinyToys

  • Members
  • 1,001 posts

Posted 24 July 2012 - 09:54 AM

This should do the trick
Spoiler

it is untested





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users