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

let 'character' move until redstone input stops

Started by vinno97, 26 April 2012 - 08:06 PM
vinno97 #1
Posted 26 April 2012 - 10:06 PM
hello,

i've downloaded a game from this forum and changed so it's controlled by redstone input (i've made a 'kinect' with pressureplates on fences). but if i want to move, i have to wait until the pressure plate turns off and touch it again.
Is there a way to let my 'character' walk until i step away from the pressure plate?
OmegaVest #2
Posted 26 April 2012 - 10:13 PM

turn = os.startTimer(0.5)
while true do
   evt, arg1, arg2 = os.pullEvent()
   if evt == "redstone" then
      if rs.getInput(side) then
         charMove = true
      elseif not rs.getInput(side) then
         charMove = false
   elseif evt == "key" and tonumber(arg1) == 16 then
      break
   elseif evt == "timer" and arg1 == turn then
      --MoveChar or not MoveChar
   end
end

Pressing 'q' will break the while loop. Side is the side you use for redstone input. Should be fairly obvious from there.
MysticT #3
Posted 26 April 2012 - 10:14 PM
It depends on how the game is made.
If it uses events, you could keep track of the redstone input, and check what changed on the redstone event. Then, if certain input is on, move the character.
If it has an update loop without events, you can use rs.getInput("side") to check if the input is on (or rs.getBundledInput for bundled cables) and move the character if it is.