Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#521 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 January 2013 - 05:24 AM

Sounds good. I'll be on the road again today, but if it is ready and not up in the first post when I get home, I will definitely put it up for ya.

#522 TheModerGuy

  • Members
  • 16 posts
  • LocationAustralia, NOT Austria!!!

Posted 21 January 2013 - 08:40 AM

Hi i'm quite new to OpenCCSensors data format, i'm making a door only open when wearing certain Armour. how would i do that?
I know i have to compare the slot with the armor item i think its: "item.hazmat.suit". all i want to do is understand how to use the getTargetDetails command

#523 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 21 January 2013 - 09:11 AM

View PostMikeemoo, on 21 January 2013 - 12:08 AM, said:

As for tanks, which tanks are you using? each mod implement the tanks differently, and unfortunately some dont implement it right!

I was using railcraft liquid loaders and iron tanks, but buildcraft liquid tanks are doing the same thing.

#524 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 21 January 2013 - 10:13 AM

View PostTheModerGuy, on 21 January 2013 - 08:40 AM, said:

Hi i'm quite new to OpenCCSensors data format, i'm making a door only open when wearing certain Armour. how would i do that?
I know i have to compare the slot with the armor item i think its: "item.hazmat.suit". all i want to do is understand how to use the getTargetDetails command

When you use the getTargetDetails command it returns a table of the target you specified. Then you get the variables out using the key. So for example to get the chest plate you would type table["Armour"]["Chestplate"]["Name"] and it would return the name of the item you have in the chest slot. Come example code to print out your armor would be
os.loadAPI("ocs/apis/sensor")
s = sensor.wrap(side)
target = s.getTargetDetails(loc)
for k, v in pairs(target.Armour) do
   write(k..": ")
   print(v["Name"])
end


#525 TheModerGuy

  • Members
  • 16 posts
  • LocationAustralia, NOT Austria!!!

Posted 21 January 2013 - 05:29 PM

View Postabihoooo, on 21 January 2013 - 10:13 AM, said:

View PostTheModerGuy, on 21 January 2013 - 08:40 AM, said:

Hi i'm quite new to OpenCCSensors data format, i'm making a door only open when wearing certain Armour. how would i do that?
I know i have to compare the slot with the armor item i think its: "item.hazmat.suit". all i want to do is understand how to use the getTargetDetails command

When you use the getTargetDetails command it returns a table of the target you specified. Then you get the variables out using the key. So for example to get the chest plate you would type table["Armour"]["Chestplate"]["Name"] and it would return the name of the item you have in the chest slot. Come example code to print out your armor would be
os.loadAPI("ocs/apis/sensor")
s = sensor.wrap(side)
target = s.getTargetDetails(loc)
for k, v in pairs(target.Armour) do
   write(k..": ")
   print(v["Name"])
end

Thank you good sir!!

this would of been apparent if my build of ccsensors was not broken :3

Edited by TheModerGuy, 21 January 2013 - 05:34 PM.


#526 TheModerGuy

  • Members
  • 16 posts
  • LocationAustralia, NOT Austria!!!

Posted 21 January 2013 - 06:02 PM

when i run this program it freezes and does nothing:

os.loadAPI("ocs/apis/sensor")
s = sensor.wrap("right")
target = s.getTargetDetails(s.getTarget())
print(k.." : "..v)
end


#527 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 January 2013 - 06:46 PM

View PostTheModerGuy, on 21 January 2013 - 06:02 PM, said:

when i run this program it freezes and does nothing:

os.loadAPI("ocs/apis/sensor")
s = sensor.wrap("right")
target = s.getTargetDetails(s.getTarget())
print(k.." : "..v)
end

Not sure what you're trying to do here. getTargets will return a table of targets, and getTargetDetails will give you details for a single one of those targets. Perhaps you're trying to do something vaguely thus:

os.loadAPI("ocs/apis/sensor")
s = sensor.wrap("right")
targets = s.getTargets()
for k, v in pairs(targets) do
  print(k)
  for dk, dv in pairs(s.getTargetDetails(k)) do
    print(dk.." : "..dv)
  end
end

You need to loop through the tables that it returns if you're trying to print out elements from those tables.

#528 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 21 January 2013 - 09:43 PM

Users are so quick to blame the software :)

#529 TheModerGuy

  • Members
  • 16 posts
  • LocationAustralia, NOT Austria!!!

Posted 22 January 2013 - 01:41 AM

View PostMikeemoo, on 21 January 2013 - 09:43 PM, said:

Users are so quick to blame the software :)

well it was crashing!

#530 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 22 January 2013 - 02:02 AM

View PostTheModerGuy, on 22 January 2013 - 01:41 AM, said:

View PostMikeemoo, on 21 January 2013 - 09:43 PM, said:

Users are so quick to blame the software :)

well it was crashing!

If there's a crash, please supply an error log.

#531 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 22 January 2013 - 08:40 AM



#532 Regelneef

  • Members
  • 37 posts
  • LocationThe Nether-lands...

Posted 22 January 2013 - 09:20 AM

OK do hope someone can help me.
I've got this setup :
Spoiler
And I see that the liquid sensor does see the Buildcraft tanks and doesn't recognize the Railcraft tanks
Spoiler
But when I upgrade the sensor to a MKII the refineries below are within reach and the programs displays information one final time and and then just exits....
Spoiler
What am I doing wrong? (I use the sensorview program btw)

#533 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 22 January 2013 - 09:22 AM

Unfortuantely, railcraft tank support was bugged in the last release and although it's been fixed it wont be available until 0.1.3.

It's to do with the whole multi-block system..

(actually, if you're playing this just in single player I'm happy to send across a custom build with the fix in)

#534 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 22 January 2013 - 02:22 PM

I've found that if the sensor is within the range of one of valve blocks it detects the tank, but still crashes only in SMP if its partially filled like with all liquid containers.

#535 Regelneef

  • Members
  • 37 posts
  • LocationThe Nether-lands...

Posted 22 January 2013 - 07:36 PM

View PostMikeemoo, on 22 January 2013 - 09:22 AM, said:

Unfortuantely, railcraft tank support was bugged in the last release and although it's been fixed it wont be available until 0.1.3.

It's to do with the whole multi-block system..

(actually, if you're playing this just in single player I'm happy to send across a custom build with the fix in)

Thnx for the offer, but we're playing SMP, on the other hand we do have 3.06b of Misc Peripherals and a backup system on the server. So I don't think that any real harm could be done :)

btw I really LOVE the gauges!!

#536 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 22 January 2013 - 09:55 PM

View Postabihoooo, on 22 January 2013 - 02:22 PM, said:

I've found that if the sensor is within the range of one of valve blocks it detects the tank, but still crashes only in SMP if its partially filled like with all liquid containers.

Any crash log you can supply would be a huge help so I can make sure it's all sorted for the next release.

#537 SNJ

  • Members
  • 2 posts

Posted 22 January 2013 - 11:56 PM

First off, thanks to all involved for creating/resurrecting this extremely useful addition. :)

I seem to be having a problem with the proximity sensor when a player goes out of range whilst the program is still iterating through the table returned by getTargets().
Take this code, for example...
os.loadAPI("ocs/apis/sensor")
local proximity = sensor.wrap("top")
repeat
  local targets = proximity.getTargets()

  term.clear()
  print("Players in range:-")

  for name, details in pairs(targets) do
	if details.Type == "Player" then	
	  local fullDetails = proximity.getTargetDetails(name)

	  if fullDetails then	
		print(fullDetails.Username)
	  end		
	end
  end
until false

With version 0.1.0, getTargetDetails() would simply return null. This was easy to deal with, as can be seen above.
Unfortunately, version 0.1.2 now chucks up the following error message instead...
sensor:8: Please specify a valid targetname

If this is intended behaviour, I'd really appreciate it if someone could show me the best way to deal with this situation.

Thanks in advance.

#538 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 23 January 2013 - 12:04 AM

Hi SNJ,

That's a bit of an oversight on my part. I've tried to add nicer error handling in there, but I guess some things should return null instead of errors..

The offending code will be in:

/ocs/apis/sensor

you can see that if the peripheral throws an ocs_error event, it'll throw an error() in the lua.

I can fix this for the next release, however, as a workaround I recommend one of the two:

1) copy ocs/apis/sensor down to the root of your computer and edit that lua method there so it returns null instead of throwing an error

or..

2) use pcall on the sensor instead.

<immibis> pcall(function, arguments...) -> status, return_values...
<immibis> status is true for success, false for error
<immibis> if it errored, there'll be one return_value, and that's the error message


#539 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 23 January 2013 - 12:12 AM

http://pastebin.com/4fLz0QvG

#540 SNJ

  • Members
  • 2 posts

Posted 23 January 2013 - 12:17 AM

Wow, that was quick. :)

Thanks Mikeemoo, I'll do as suggested.

Cheers.

[edit]
You posted again as I was replying.

That's great. Thanks *very* much. :D
[/edit]





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users