Jump to content




OpenCCSensors sensor.getTargets() won't return table?


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

#1 MoscowModder

  • Members
  • 3 posts

Posted 06 October 2013 - 12:33 PM

I'm familiar with programming in general but new to LUA and ComputerCraft. I decided (perhaps rashly) to try making an elevator for my first project. I'm directly copying everything, including the PasteBin code, from this video. I'm pretty sure I set up everything exactly like it was in the video (except with only 2 floors, not 6), but every time I select a floor, I get the error on line 38 that sensor.getTargets() returns a number when the program expects a table (with pairs).

Here is the code I'm using (not written by me).

I've tried placing both of the two sensor cards (inventory and proximity) in the Turtle's slot 16, but both return an error. I've verified with sensorView that there is sensor data on the left sensor, which shows my player stats for the proximity sensor and the two dispensors in the inventory card's display.

If it makes a difference, I'm using the latest version of FTB Ultimate on Minecraft 1.5.2, plus I downloaded the latest vesion of OpenCCSensors for 1.5.2 to use this code.

Edit: I made a test program to try to output the table from each sensor - tried it with each of the two sensors (again, inventory and proximity) and got numbers from both.

Edit 2: The program interacts with another computer (per floor) running this code (also not by me) to handle cart dispensing.

Edited by Lyqyd, 06 October 2013 - 05:37 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 October 2013 - 05:37 PM

Split into new topic.

The code you're using is from an old version. You'll need to load the sensor API (ocs/apis/sensor) and use sensor.wrap to wrap your sensor peripheral (don't put it in a variable named sensor!). With those two changes, it should start working, if the rest of the code is correct.

#3 MoscowModder

  • Members
  • 3 posts

Posted 06 October 2013 - 10:28 PM

Thanks! Now it doesn't give me the error... but it doesn't call the cart or tell me one is coming. It shifts around the sensor cards but doesn't make the elevator work.

Here's my update to elevator.main:
Spoiler


#4 MoscowModder

  • Members
  • 3 posts

Posted 08 October 2013 - 08:38 PM

Update: I edited checkIfCart() to always return true, and the program now spawns Minecarts as it should. The problem is, neither the boarding track nor the elevator rails get powered to launch the cart. Can anyone figure this out? Or else point me to a more recent, better-working elevator program?

#5 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 09 October 2013 - 09:22 AM

There are only two instances of setting the redstone output to true in this program, and they are both in the handleMain function. The conditions to turn the redstone on are:
    elseif message.command == "floorSelect" then
        if message.floorId == config.id then
            rs.setOutput("front", true)

elseif message.command == "gotCart" then
  if needCart and not gotCartResponse then
      rs.setOutput("front", true)

I've deleted any extraneous code in there. If neither of these conditions evaluate to true, you're not going to be powering the rail. See if you can't check these conditions and fix the problem. I don't have time to sift through all of the code right now, but I'll check back later and see what I can do.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users