Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#981 Conan1981m

  • Members
  • 28 posts

Posted 09 June 2013 - 05:01 AM

Well i understand that its really a different way of reading and packing the data from both of the mods ..

So maybe anyone can make some handler table, for splitting the table to the code we would need,
means if i want to filter
"Day" true i have to ... i dont know ..
i just get a huge table .. how do i do this ?

#982 ZagKalidor

  • Members
  • 111 posts

Posted 09 June 2013 - 09:40 AM

You could do as follows

os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")

local details2 = prox.getTargetDetails('CURRENT')
print (textutils.serialize(details2))


local dimension=textutils.serialize(details2["Dimension"])
print (("Dimension :") .. dimension)

local thunder=textutils.serialize(details2["Thundering"])
print (("Thundering :") .. thunder)

local biome=textutils.serialize(details2["Biome"])
print (("Biome :") .. biome)

local daytime=textutils.serialize(details2["Daytime"])
print (("Daytime :") .. daytime)

Thundering and Daytime will give back a boolean

Of course, this code could be made easier, but i think, its nice to understand the structure of the table.

As you see, using the sensorview programm, the target is named "CURRENT". If you print out the target.Details of ('Current'), you will receive the table with its implemented fields.
If you put the content of the field ["Daytime"] to the variable daytime, you can handle it what you like.

World Sensor has a nice and easy table, since it is not nested like, for example, a chest

the nested fieldcontent of a chestslot would look something like this:

local details1 = prox.getTargetDetails('3,1,-1') --the chest you want to spot

for slotnumber = 1, 27 do
stackcontent1=textutils.serialize(details1["Slots"][slotnumber]["Size"])
stackmax1=textutils.serialize(details1["Slots"][slotnumber]["MaxStack"])
inname1=textutils.serialize(details1["Slots"][slotnumber]["Name"])
end
print bla bla bla

This would show you all 27 Slots of a chest and its maximum Stacksize with the name of the Item inside the Slot.

#983 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 09 June 2013 - 09:43 AM

could add some sensor cards modules to modular powersuits power armor to your mod, so you are able to get information between your mod and modular power suits?

#984 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 09 June 2013 - 11:25 AM

View PostJappards, on 09 June 2013 - 09:43 AM, said:

could add some sensor cards modules to modular powersuits power armor to your mod, so you are able to get information between your mod and modular power suits?

I don't really understand what you're asking for here.

#985 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 09 June 2013 - 12:04 PM

I think he means getting the energy level and heat level of a powersuit. Perhaps the modules as well.

#986 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 09 June 2013 - 01:44 PM

yes, and also the health, hunger, breath, if the player is sprinting, etc.

#987 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 June 2013 - 01:55 PM

View PostZagKalidor, on 09 June 2013 - 09:40 AM, said:

You could do as follows

os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")

local details2 = prox.getTargetDetails('CURRENT')
print (textutils.serialize(details2))


local dimension=textutils.serialize(details2["Dimension"])
print (("Dimension :") .. dimension)

local thunder=textutils.serialize(details2["Thundering"])
print (("Thundering :") .. thunder)

local biome=textutils.serialize(details2["Biome"])
print (("Biome :") .. biome)

local daytime=textutils.serialize(details2["Daytime"])
print (("Daytime :") .. daytime)

Thundering and Daytime will give back a boolean

Of course, this code could be made easier, but i think, its nice to understand the structure of the table.

As you see, using the sensorview programm, the target is named "CURRENT". If you print out the target.Details of ('Current'), you will receive the table with its implemented fields.
If you put the content of the field ["Daytime"] to the variable daytime, you can handle it what you like.

World Sensor has a nice and easy table, since it is not nested like, for example, a chest

the nested fieldcontent of a chestslot would look something like this:

local details1 = prox.getTargetDetails('3,1,-1') --the chest you want to spot

for slotnumber = 1, 27 do
stackcontent1=textutils.serialize(details1["Slots"][slotnumber]["Size"])
stackmax1=textutils.serialize(details1["Slots"][slotnumber]["MaxStack"])
inname1=textutils.serialize(details1["Slots"][slotnumber]["Name"])
end
print bla bla bla

This would show you all 27 Slots of a chest and its maximum Stacksize with the name of the Item inside the Slot.

That is some awful code. You don't need any of those textutils.serialize calls at all. What are they supposed to do?

Is the confusion about how to get data out of the tables because you don't know about sensorview, or is it because the interface isn't as well-documented as it could be?

#988 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 09 June 2013 - 02:01 PM

View PostJappards, on 09 June 2013 - 01:44 PM, said:

yes, and also the health, hunger, breath, if the player is sprinting, etc.

I'm not sure what this has to do with modular powersuits.

Most of that information is already available.

#989 Jappards

  • Validating
  • 116 posts
  • LocationHolland

Posted 09 June 2013 - 02:18 PM

well, i want that you are able to integrate sensors into your power armor, because what if i go somewhere where there aren`t any sensors?

#990 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 09 June 2013 - 02:21 PM

View PostJappards, on 09 June 2013 - 02:18 PM, said:

well, i want that you are able to integrate sensors into your power armor, because what if i go somewhere where there aren`t any sensors?

Sorry, what I think it is you want isn't going to happen.

#991 ZagKalidor

  • Members
  • 111 posts

Posted 09 June 2013 - 03:16 PM

is the confusion about how to get data out of the tables because you don't know about sensorview, or is it because the interface isn't as well-documented as it could be?



Sorry but i thought that could be a acceptable explanation from beginner to beginner, just to understand a part of it. Of course it is awful code but it was meant to be that easy. I will never get a pro but i do my own programs with your stuff and as long as they do what i want, its good for me. I dont quite understand what you mean with "you dont know about sensorview" I do and i mentioned it. Where can i find any part of documentation about it? I studied the sourcecode of Sensorview and made my own ideas out of it. You should not forget, that some beginners that had never to do with coding, cant get through such sourcecode as it should be. I think everything i read about lua and OCS is written by pros - for pros or at least semi-pros. Bloody Beginners start with it and make their own thoughts. There are people around that do not even no what a boolean is.

I'm sorry for hurting your eyes with this shitty code.

But now you'll have to show how a pro like you does it. - please.

#992 ZagKalidor

  • Members
  • 111 posts

Posted 09 June 2013 - 03:32 PM

No I'm sorry

shurely you dont have to, you did it enough before.

Some source code is often too pro to understand, we have do work on ourself to get through.

Sorry again, didn't want to bore you or upset or something

#993 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 June 2013 - 03:45 PM

Your code would have been better written like this:

os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")

local details = prox.getTargetDetails('CURRENT')
for k,v in pairs(details) do
    print(tostring(k)..": "..tostring(v)
end

print (("Dimension :") .. details.Dimension)
print (("Thundering :") .. details.Thundering)
print (("Biome :") .. details.Biome)
print (("Daytime :") .. details.Daytime)

Note that you don't need textutils.serialize at all.

I didn't see mention of sensorview when I read through your post originally. I did notice your post a few posts up talking about it taking hours to determine what to index in order to get the information you desired from the table, so I was inquiring as to whether you hadn't known about sensorview, or if the interface was causing confusion. Each layer of indentation is a table nested inside the main table, so when you see something like:

Tanks>
  1>
    Amount: 0
    Capacity: 16000

That would show that you'd need to index details.Tanks[1].Amount to get the amount currently in the tank.

#994 ZagKalidor

  • Members
  • 111 posts

Posted 09 June 2013 - 04:02 PM

Thx Pro,

hopeConan1981m gets it like me.

I'll have to get used to this object thinking. I always try to put everthing into some kind of variable to ask for it. My old "Basic" ways. We are not on a VIC-20 these days

#995 Raevox

  • New Members
  • 1 posts

Posted 09 June 2013 - 05:05 PM

Need a lil' bit of help; I tried following the graph example at the end of the OP, but I get this error upon running my program (using OCS v1.5.2.0):
graph:17:attempt to call nil

I am writing a program for my CRCS reactor; I want my nuker to auto-shutoff during module swaps (when the heat starts to go up). Here is my current code:
os.loadAPI("ocs/apis/sensor")
os.loadAPI("ocs/apis/graph")

local mechSen = sensor.wrap("top")
local nuker = mechSen.getTargetDetails("0,1,2")
local heatLevel = nuker.Heat
local signal = false
local monitor = peripheral.wrap("left")

function checkHeat()
  if heatLevel == 0 then
	signal = false
  else
	signal = true
  end
  return heatLevel
end

function setRsSignal()
  rs.setOutput("back", signal)
  return
end

nukerGraph = graph.new("monitor", checkHeat, "Nuker Heat Level", nil, 0, 10000)

while true do
  os.queueEvent("beep-boop")
  os.pullEvent()

  checkHeat()
  setRsSignal()
  nukerGraph:draw()
end
The error goes away if I remove/comment out "nukerGraph:draw()," but that means no graph. Any help would be greatly appreciated.

#996 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 June 2013 - 09:17 PM

Give this a shot:

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

local mechSen = sensor.wrap("top")
local nuker = mechSen.getTargetDetails("0,1,2")
local heatLevel = nuker.Heat
local monitor = peripheral.wrap("left")

--this function needs to actually get the heat each time it is called, not just use the initial heat value.
function checkHeat()
	local heatLevel = mechSen.getTargetDetails("0,1,2").Heat
	if heatLevel == 0 then
		rs.setOutput("back", false)
	else
		rs.setOutput("back", true)
	end
	return heatLevel
end

--this function can be refactored away.

--removed quotes around monitor.
nukerGraph = graph.new(monitor, checkHeat, "Nuker Heat Level", nil, 0, 10000)

while true do
	os.queueEvent("beep-boop")
	os.pullEvent()

	--:draw() will call the update function you told it to use, so you will not need to call it yourself as well.
	nukerGraph:draw()
end


#997 ZagKalidor

  • Members
  • 111 posts

Posted 10 June 2013 - 05:05 AM

ask a pro:

is there any way to call some function while i'm in a os.pullEvent? I tried parallel.waitForAny / All but with no satisfying result...

#998 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 10 June 2013 - 05:24 AM

View PostZagKalidor, on 10 June 2013 - 05:05 AM, said:

ask a pro:

is there any way to call some function while i'm in a os.pullEvent? I tried parallel.waitForAny / All but with no satisfying result...


Check out the rom/programs/computer/worm game

From what I remember, it adds a timer to the script. If the event it pulls is a timer script, it adds another timer. If it's a different event type, it does something.

#999 Calimore

  • Members
  • 28 posts

Posted 10 June 2013 - 03:18 PM

Hi there, may I ask a quick question...

Is there a sort of easy way to add crops from different mods to be recognised by the crops sensor card?

I know you can't support every mod there is, but there's a nice little (mostly unknown?) mod for the farmer in me called "Jaffas and more" (http://jaffaswiki.tk/wiki/) which adds additional crops to the game. Is there any way to get those detected by a crop sensor card?

#1000 ZagKalidor

  • Members
  • 111 posts

Posted 10 June 2013 - 07:08 PM

View PostMikeemoo, on 10 June 2013 - 05:24 AM, said:

View PostZagKalidor, on 10 June 2013 - 05:05 AM, said:

ask a pro:

is there any way to call some function while i'm in a os.pullEvent? I tried parallel.waitForAny / All but with no satisfying result...


Check out the rom/programs/computer/worm game

From what I remember, it adds a timer to the script. If the event it pulls is a timer script, it adds another timer. If it's a different event type, it does something.

Hey, thank you very much. It really solved my problem.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users