Jump to content




OCS problem


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

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 11 April 2016 - 12:58 PM

os.loadAPI('ocs/apis/sensor')
while true do
  handle = sensor.wrap('left').getTargets()
  if handle.sewbacca then
    local pos = handle.sewbacca.Position.X
    local pos2 = handle.sewbacca.Position.Z
    if pos > pos2 then pos = pos else pos = pos2 end
    if pos <= 2 then
      redstone.setOutput('top', true)
    else
      redstone.setOutput('top', false)
    end
  else
	redstone.setOutput('top', false)
  end
  sleep(0)
end

I want to create an auto door opener.
This script doesn't works (The door doesn't open/close)

(Scanner Proximity Card Mk. I)

Edited by Sewbacca, 11 April 2016 - 03:59 PM.


#2 Bomb Bloke

    Hobbyist Coder

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

Posted 11 April 2016 - 01:46 PM

Using print() calls, pinpoint the exact "if" branch that isn't going in the direction you expect, and get it to tell you what the relevant variables are set to at that time.

#3 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 11 April 2016 - 03:40 PM

View PostBomb Bloke, on 11 April 2016 - 01:46 PM, said:

Using print() calls, pinpoint the exact "if" branch that isn't going in the direction you expect, and get it to tell you what the relevant variables are set to at that time.
It seems like the while loop will runs just one time.

#4 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 11 April 2016 - 04:01 PM

Check the API file. It may be calling 'break'

#5 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 11 April 2016 - 04:38 PM

View PosteveryOS, on 11 April 2016 - 04:01 PM, said:

Check the API file. It may be calling 'break'

That isn't how break works. Break isn't a function rather than a statement, you can only break out of a loop in the same function.

#6 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 11 April 2016 - 05:34 PM

View PosteveryOS, on 11 April 2016 - 04:01 PM, said:

Check the API file. It may be calling 'break'

SquidDev is right, but also I have just this code.

Edited by Sewbacca, 11 April 2016 - 05:38 PM.


#7 EveryOS

  • Members
  • 570 posts
  • LocationOver there ->

Posted 11 April 2016 - 06:07 PM

View PostSquidDev, on 11 April 2016 - 04:38 PM, said:

View PosteveryOS, on 11 April 2016 - 04:01 PM, said:

Check the API file. It may be calling 'break'

That isn't how break works. Break isn't a function rather than a statement, you can only break out of a loop in the same function.
I meant, like,
function breakAPI.doBreak()
  break
end


#8 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 11 April 2016 - 07:22 PM

View PosteveryOS, on 11 April 2016 - 06:07 PM, said:

I meant, like,
function breakAPI.doBreak()
  break
end

View PostSquidDev, on 11 April 2016 - 04:38 PM, said:

That isn't how break works. Break isn't a function rather than a statement, you can only break out of a loop in the same function.

while true do
  break -- Valid. Inside a loop
end

break -- Invalid: outside a loop (you get a "invalid: no loop to break" syntax error when compiling)

local function doBreak() break end
while true do
  doBreak() -- Invalid: doBreak doesn't know anything about this loop. From its perspective, it isn't in a loop. You'll get the same error as above.
end

Edited by SquidDev, 11 April 2016 - 07:24 PM.


#9 Bomb Bloke

    Hobbyist Coder

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

Posted 11 April 2016 - 10:34 PM

If the loop isn't repeating, then the most likely point of failure is your sensor call. Break it up into multiple lines, stick in more print statements, isolate the exact call that terminates the script.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users