Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#481 SteveofDoom

  • Members
  • 4 posts

Posted 19 January 2013 - 12:00 PM

Hey, everyone, I'm new to this forum.
I love this mod but I encountered a bug. When I run my program once it works normally, but the second time I run it, it breaks everything and I have to reboot the PC to make it work again.
Using version 0.1. In 0.12 pre 1 the sensorview program doesn't work and sensors are very buggy so I decided to stay on 0.1.
This is the code:
-- Init:
os.loadAPI("ocs/apis/sensor")
local player = {...}
local side = {"top", "bottom", "front", "back", "left", "right"}
if #player < 1 then
print("Usage: monplayerdbg <player name>")
return
end
for i=1, 6 do
if peripheral.getType(side[i]) == "sensor" then
  sensor = sensor.wrap(side[i])
  if sensor.getSensorName() == nil then
   textutils.slowWrite("No sensor card detected! \n") sleep(0.5)
   return
  end
  if string.sub(sensor.getSensorName(), 20) == "proximitysensor" then
   prox = sensor.wrap(side[i])
  elseif sensor.getSensorName ~= nil then
   textutils.slowWrite("Invalid sensor card detected! \n")
   sleep(0.5)
   return
  end
end

if peripheral.getType(side[i]) == "monitor" then
  mon = peripheral.wrap(side[i])
end
end

-- Functions:
function monUpdate(name, x, y, z)
mon.clear()
mon.setCursorPos(1, 1)
mon.write(name..":")
mon.setCursorPos(1, 2)
mon.write("X: "..x)
mon.setCursorPos(1, 3)
mon.write("Y: "..y)
mon.setCursorPos(1, 4)
mon.write("Z: "..z)
end
function refresh()
targets = sensor.getTargets()
term.clear()
term.setCursorPos(1, 1)
end

-- Code:
while true do
refresh()
for n, i in pairs(targets) do
  if i.type == "Player" then
   if n == tostring(player[1]) then
	--print(n.." "..tostring(i.Position.X).." "..tostring(i.Position.Y).." "..tostring(i.Position.Z))
	--rs.setOutput("left", isInArea(n, i.Position.X, i.Position.Y, i.Position.Z))
	monUpdate(n, i.Position.X, i.Position.Y, i.Position.Z)
   end
  end
end
end

Tried running the sensorview program after running this one and it breaks it when I select the side the sensor is on and outputs "attempt to call nil" at line 63. I assume it breaks the whole sensor to variable assignment as in my program it points to line 14 which is "sensor = sensor.wrap(side[i])". I'd really like that this gets fixed.

#482 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 January 2013 - 12:06 PM

Stealth update to the same download link

#483 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 January 2013 - 12:55 PM

SteveofDoom, You're overwriting the "sensor" variable with sensor.wrap(). If you do that, it no longer knows what the sensor api is, so it'll break.

"sensor = sensor.wrap(side[i])"

change that to "somethingelse = sensor.wrap(side[i])"


Also, if you're experiencing bugs in the pre-release 0.1.2, it'd be extremely handy to know what those bugs are, because I'm unaware of what bugs there are until people report them. If I knew of bugs I'd have fixed them and wouldn't have put out the preview release! :)

#484 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 January 2013 - 12:57 PM

If anyones trying out the preview release, please make sure you delete the mods/OCSLua folder and restart your client/server to make sure it regenerates it. I'll add something in before the proper release to make sure this happens automatically.

#485 Cosford

  • New Members
  • 3 posts

Posted 19 January 2013 - 02:53 PM

Hi guys!

Just recently started with CC, and hoping to implement some of these here sensors into some programs I'm planning on making.
However, I can't seem to find a full list of the calls to each sensor's API's? (Forgive the <likely> incorrect use of words here, only dabbled in a small amount of programming,)

Where would I find this?

Cheers. :)

#486 MichiyoRavencroft

  • Members
  • 10 posts

Posted 19 January 2013 - 04:17 PM

Get this error on a 1.4.7 server running forge .497, and OpenCCSensors-0.1.2-pre1 Client starts with no issue.
Spoiler


#487 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 January 2013 - 04:22 PM

View PostCosford, on 19 January 2013 - 02:53 PM, said:

Hi guys!

Just recently started with CC, and hoping to implement some of these here sensors into some programs I'm planning on making.
However, I can't seem to find a full list of the calls to each sensor's API's? (Forgive the <likely> incorrect use of words here, only dabbled in a small amount of programming,)

Where would I find this?

Cheers. :)

Most of the sensor cards don't have specific calls for that card. You'll want to use the getTargets and getTargetDetails methods quite a bit, though. These will be how you gather most of the information from the cards, and they are documented in the first post.

Mikee, I poked some pixels and came up with this:

Posted Image

Feel free to use (or not use!) any subset of it. The file itself is in the expected place on my fork. Hopefully the tiering is a little clearer in-game without going full-on pastel ponies. Also mucked about with the upgrade icons. I kind of like the amps, but not sure I care for my re-worked antenna. Curious as to what the rest of the team thinks.

#488 jewelshisen

  • Members
  • 164 posts

Posted 19 January 2013 - 04:30 PM

View PostLyqyd, on 19 January 2013 - 04:22 PM, said:


Mikee, I poked some pixels and came up with this:

Posted Image

Feel free to use (or not use!) any subset of it. The file itself is in the expected place on my fork. Hopefully the tiering is a little clearer in-game without going full-on pastel ponies. Also mucked about with the upgrade icons. I kind of like the amps, but not sure I care for my re-worked antenna. Curious as to what the rest of the team thinks.

I may not be on the staff but I like the new borders. They look quite a bit better than before.

#489 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 January 2013 - 11:53 PM

View PostNeoRavencroft, on 19 January 2013 - 04:17 PM, said:

Get this error on a 1.4.7 server running forge .497, and OpenCCSensors-0.1.2-pre1 Client starts with no issue.
Spoiler

Perfect! thank you! This'll be fixed this morning.

#490 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 12:26 AM

https://dl.dropbox.c...-0.1.2-pre2.zip

0.1.2, pre-release 2, this fixes the server issue. Sorry for it taking so long, I was asleep! :)

Changes:
- Should now run fine on servers
- Added Lyqyds icons

#491 SteveofDoom

  • Members
  • 4 posts

Posted 20 January 2013 - 01:42 AM

@Mikeemoo:
I don't know why was I so stupid about that sensor = stuff.
There is a bug where the sensorview program freezes and you have to terminate it when you select the side the sensor is on. It stops responding.

EDIT: Does anyone know how to use 1 write line to print several lines on a monitor? The \n doesn't work when done using the mon.write command but it works when used with write and textutils.slowWrite commands.
It also isn't possible to list through details (sensorview program) using Page Up/Down in v0.1

#492 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 01:54 AM

View PostSteveofDoom, on 20 January 2013 - 01:42 AM, said:

@Mikeemoo:
I don't know why was I so stupid about that sensor = stuff.
There is a bug where the sensorview program freezes and you have to terminate it when you select the side the sensor is on. It stops responding.

I need more info than that! Does this always happen? Below this you mention that you're unable to scroll through targets so I'm guessing this doesnt always hang when you're selecting a side? Do you have any steps to recreate this issue, as sensorview works well for everyone else.. which card are you using? Have you tried deleting your /mods/OCSLua folder and restarting the client? Have you recently upgraded version? ..etc..etc..etc.

As for your second issue with the Page Up/Page Down, this has nothing to do with sensorview - I'm guessing you have NEI enabled, which is taking over and doesn't send the key events down to computercraft. Press O to turn off the NEI menu and try again.

#493 Marval

  • Members
  • 47 posts

Posted 20 January 2013 - 02:56 AM

Can somebody give me a example of function which return amount of items in chest on specified x,y,z?
something like this:

amount = GetAmount(1,0,-1)

I would be grateful.
I tried something like this:


function GetAmount(x,y,z)
Coords = ""..x..","..y..","..z..""
Details = sensor.call("top", "getTargetDetails", Coords)
return Details
end

but I don't know what exactly return, Details.count, Details.amount or what?

#494 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 06:45 AM

View PostMarval, on 20 January 2013 - 02:56 AM, said:

Can somebody give me a example of function which return amount of items in chest on specified x,y,z?
something like this:

amount = GetAmount(1,0,-1)

I would be grateful.
I tried something like this:


function GetAmount(x,y,z)
Coords = ""..x..","..y..","..z..""
Details = sensor.call("top", "getTargetDetails", Coords)
return Details
end

but I don't know what exactly return, Details.count, Details.amount or what?

Which version of OCS are you using?

in 0.1.2, it'll be like this:

os.loadAPI("ocs/apis/sensor")

local inventory = sensor.wrap("right")

function getAmount(target)
  local count = 0
  local details = inventory.getTargetDetails(target)
  for slot, stack in pairs(details.Slots) do
    count = count + stack.Size
  end
  return count
end

In 0.1.0 I *think* it'd be like this:

os.loadAPI("ocs/apis/sensor")

local inventory = sensor.wrap("right")

function getAmount(target)
  local count = 0
  local details = inventory.getTargetDetails(target)
  for slot, stack in pairs(details) do
    count = count + stack.Size
  end
  return count
end

(I seem to remember making "slots" a sub property of the results set in the latest version because it made more sense)

#495 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 06:47 AM

Has anyone experienced any issues with 0.1.2? If not, I'll prepare a proper 0.1.2 release and update the first post.

#496 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 07:41 AM

Version 0.1.2 released:

https://dl.dropbox.c...nsors-0.1.2.zip


Gauges now have a recipe.

I'll write up a new front page with documentation of the new features.

#497 Marval

  • Members
  • 47 posts

Posted 20 January 2013 - 09:30 AM

With inventory sensor i can only check inventories that are next to the sensor? Getting information about target f.e. 2,0,0 doesn't work :(

#498 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 09:40 AM

View PostMarval, on 20 January 2013 - 09:30 AM, said:

With inventory sensor i can only check inventories that are next to the sensor? Getting information about target f.e. 2,0,0 doesn't work :(/>/>

If you let me know what version you're using I can be more help.

in version 0.1.0 the target "2,0,0" will work just fine. If you're using version 0.1.2, you'll need create a Signal Boost Antenna and craft it with your mk1 card to make a mk2.

The boost antenna is the left recipe here:

Posted Image

(this will be documented at some point tonight/tomorrow)

#499 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 January 2013 - 10:30 AM

First post updated with more/new information

#500 Cosford

  • New Members
  • 3 posts

Posted 20 January 2013 - 10:48 AM

Hi, thanks for your reply.

Sorry, I'm still not grasping this very well.

Please see below this quote:

Quote

It's my understanding that something like this:

local targets = prox.getTargets()

will assign the targets variable as a table with different types of information in it? (eg, health, armor)

How would I access those 'keys' <I believe they are called?> so that I know what to call with something like:

print("Health: "..moreDetails.<Keygoeshere?>)

Cheers :)


EDIT: Woh, well I managed to finally print the output of the keys with the following:

local moreDetails = prox.getTargetDetails("Cosford")
print(textutils.serialize(moreDetails))

But I ended up with page upon page of output texts, so I can't see many of them :P Is there a list somewhere?

Okay, so my understanding has changed somewhat.
Using the sample code in the first post as an example, I'd like to see a list of the keys that can be put in place of 'Health' in the following code:

  -- get more details about them
  local moreDetails = prox.getTargetDetails(name)
  -- print their health
  print("Health: "..moreDetails.Health)

I have attempted printing all of them for a player using:
local moreDetails = prox.getTargetDetails("Cosford")
print(textutils.serialize(moreDetails))
However, this yielded with page upon page of output which is difficult to read. Is there some documentation somewhere that I've failed to see which shows this list?

Cheers,
Cosford.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users