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

Elevator issue /java codes in lua?

Started by Hocico, 20 January 2017 - 08:03 PM
Hocico #1
Posted 20 January 2017 - 09:03 PM
Hello,

the following code is ment to be an elevator program. It's written with expressions from Java (cause I don't know how these expressions look in lua and don't know if they exist in lua)

I want the program to make the elevator to go up then I push a button (top side and back of the computer) and go down when I push an other button (left side and right side of the computer)

SpoilerI want the programm running (even) then just one of the 4 buttons get acvitated. The elevator shall keep the redstonesignal online till a button for going down is activated. and keeping it offline till a button to going up is activated. The Redstonesignal the computer shall put out goes to 9 "extended Drawbridges" from "Tinkers' Mechworks"



when(rs.getInput("right") || rs.getInput("left")) = true {

rs.setOutput("bottom", false)

}

when(rs.getInput("top") || rs.getInput("back")) = true {

rs.setOutput("bottom", true)

}


when I try to run the Program I get an error:
bios:14: [string] "Elevator"]:1: ')' expected

Can someone tell me whats the issue in line 1? Are there any other issues you can se comming? Does this code work in lua anyway, or are these java-based expressions nonsense for lua?


Thanks a lot for your help ;-)
Edited on 20 January 2017 - 08:11 PM
KingofGamesYami #2
Posted 20 January 2017 - 10:08 PM
That's pretty much nonsense for lua.
I know both Java and Lua, here's a quick overview:
*Brackets make tables, not what you wanted
* || is 'or', && is 'and'
* there's no such thing as "when"
Your code might look something like this:

while true do --#loop infinately
  if rs.getInput( "right" ) or rs.getInput( "left" ) then --# check for right or left
    rs.setOutput("bottom", false)
  end

  if rs.getInput( "top" ) or rs.getInput( "back" ) then --#check for top or back
    rs.setOuput( "bottom", true )
  end

  os.pullEvent( "redstone" ) --# wait for a redstone event (in CC programs, you must *always* yield)
end
Edited on 20 January 2017 - 09:08 PM
Lupus590 #3
Posted 20 January 2017 - 10:08 PM
I don't know Java (it's on my to learn list) but I think I've translated your example code to Lua correctly.


if (rs.getInput("right") or rs.getInput("left")) then
  rs.setOutput("bottom", false)
end
if (rs.getInput("top") or rs.getInput("back")) then
  rs.setOutput("bottom", true)
end

edit: I saw the notification for Admicos' post but how did I get ninja'd by Yami?
Edited on 20 January 2017 - 09:09 PM
Hocico #4
Posted 20 January 2017 - 11:10 PM
Thanks a lot guys!!

" * || is 'or', && is 'and' "
uh… ok…

" * there's no such thing as "when" "

That explanes why I couldn't find something via google^^

all in all I just can say : Oh my God what a mess :huh:/> lua is…… different :wacko:/>

But thanks a lot anyway. And thanks for the link, too. ;)/>
Dragon53535 #5
Posted 21 January 2017 - 07:43 AM
Also, string concatenation is '..' instead of '+'