Jump to content




CC Elevator | Mod Version 1.33 | Need help diagnosing


5 replies to this topic

#1 GamersUnited556

  • Members
  • 16 posts
  • LocationUnited States, Texas

Posted 04 August 2018 - 04:51 PM

I have started a code to make an elevator, It uses two separate timer loops to determine to go up or down based on elevator position and selected floors.
But the math functions in the code are messing up with negative values.
--[[ Local variables ]]

local termWidth, termHeight = term.getSize()
local selectedItem = 1
local a = 0 -- Current floor in block height
local b = 0 -- Selected floor in block height
local c = 0 -- Floor block height difference
local d = 0 -- Absolute value of c for timer loop
local running = true
--[[ Menu Methods ]]
function e() -- Math / Timer Function
  if rs.getBundledOutput("back",colors.white)==true then
    a = 0
  elseif rs.getBundledOutput("back",colors.black)== true then
a = -5
  elseif rs.getBundledOutput("back",colors.red)== true then
a = -10
  elseif rs.getBundledOutput("back",colors.green)== true then
a = -15
  end -- Value of a is negative to
 
  c = a + b
  d = math.abs(c)
 
  if c > 0 then -- Timer loop to go down
    for x=1, d do
   rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.blue))
	  sleep(.2)
   rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.blue))
   sleep(.2)
end
  elseif c < 0 then -- Timer loop to go up
    for x=1, d do
   rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.gray))
	  sleep(.2)
   rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.gray))
   sleep(.2)
end
  elseif c == 0 then
    return
  end
end
function C1() -- Floor selection to give wanted height variable
  if rs.getBundledOutput("back",colors.white)==true then
    return
  else
b = 0
e(B)/>
  end
end
function C2()
  if rs.getBundledOutput("back",colors.black)==true then
    return
  else
b = 5
e(B)/>
  end
end
function C3()
  if rs.getBundledOutput("back",colors.red)==true then
    return
  else
b = 10
e(B)/>
  end
end
function C4()
  if rs.getBundledOutput("back",colors.green)==true then
    return
  else
b = 15
e(B)/>
  end
end

--[[ Menu Definitions ]]

mainMenu = {
  [1] = { text = "1st Floor", handler = C1},
  [2] = { text = "2nd Floor", handler = C2},
  [3] = { text = "3rd Floor", handler = C3},
  [4] = { text = "4th Floor", handler = C4}
}

--[[ Printing Methods ]]

function printMenu( menu )
  term.clear()
  term.setCursorPos(1,1)
  print("-=Please Select a Floor=-")
  term.setCursorPos(1,2)
  for i=1,#menu do
    if i == selectedItem then
	  print(">> "..menu[i].text)
    else
	  print("   "..menu[i].text)
    end
  end
end

--[[ Handler method ]]

function onKeyPressed(key, menu)
  if key == 28 then
    onItemSelected(menu)
  elseif key == 200 then
    if selectedItem > 1 then
	  selectedItem = selectedItem - 1
    end
  elseif key == 208 then
    if selectedItem < #menu then
	  selectedItem = selectedItem + 1
    end
  end
end

function onItemSelected( menu )
  menu[selectedItem].handler()
end

--[[ Main method ]]
function main()
    while running do
	  printMenu(mainMenu)
	  event, key = os.pullEvent("key")
	  onKeyPressed(key,mainMenu)
   e()
    end
  end
end
main()
https://pastebin.com/kJLrcGnp

in that program it won't switch to the separate timer loops using the greater than or less than functions, but in the program below which is part of the code
to test it works and detects negatives.
function test()
  term.clear()
  term.setCursorPos(1,1)
  local a = 5
  local b = 10
  local c = 0
  if a > b then --Similar code used in the main program as example
    a = a * -1
    rs.setOutput("right",true)
  elseif a < b then
    a = a * -1
    rs.setOutput("left",true)
  end

  c = a + b
  print(c)
end
test()
https://pastebin.com/qa102SWD

Any help would be appriciated

Edited by GamersUnited556, 04 August 2018 - 05:09 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 04 August 2018 - 08:44 PM

You might try using redstone.getBundledOutput correctly, assuming you have some other function/program that would set those output colors in the first place.

#3 GamersUnited556

  • Members
  • 16 posts
  • LocationUnited States, Texas

Posted 04 August 2018 - 09:15 PM

View PostLyqyd, on 04 August 2018 - 08:44 PM, said:

You might try using redstone.getBundledOutput correctly, assuming you have some other function/program that would set those output colors in the first place.
Should have mentioned that this version is modified to accept a 2nd string for colors for the bundled cables get output.

Edited by GamersUnited556, 04 August 2018 - 09:21 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 August 2018 - 01:20 AM

Can't really comment on whether your modified function is working without seeing the code for it. But I suggest that you use some print() and type() calls to ensure that it's giving you the output you're expecting.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 August 2018 - 08:50 PM

View PostGamersUnited556, on 04 August 2018 - 09:15 PM, said:

View PostLyqyd, on 04 August 2018 - 08:44 PM, said:

You might try using redstone.getBundledOutput correctly, assuming you have some other function/program that would set those output colors in the first place.
Should have mentioned that this version is modified to accept a 2nd string for colors for the bundled cables get output.

Emphasis added. You're passing it a number. As Bomb Bloke said, we'd need to see the modified function.

Also, please confirm that you are, in fact, setting those bundled outputs in some other piece of code running on the computer. If so, please post that code as well. If not, you'll need to set those outputs at some point.

#6 Ta©ti_Tac0Z

  • Members
  • 59 posts

Posted 12 August 2018 - 11:16 PM

wait elevetor? so a redstone elevator controlled by a CC computer? or a sperated mod?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users