#981
Posted 09 June 2013 - 05:01 AM
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
Posted 09 June 2013 - 09:40 AM
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
Posted 09 June 2013 - 09:43 AM
#985
Posted 09 June 2013 - 12:04 PM
#986
Posted 09 June 2013 - 01:44 PM
#987
Posted 09 June 2013 - 01:55 PM
ZagKalidor, on 09 June 2013 - 09:40 AM, said:
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?
#989
Posted 09 June 2013 - 02:18 PM
#991
Posted 09 June 2013 - 03:16 PM
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
Posted 09 June 2013 - 03:32 PM
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
Posted 09 June 2013 - 03:45 PM
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
Posted 09 June 2013 - 04:02 PM
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
Posted 09 June 2013 - 05:05 PM
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
Posted 09 June 2013 - 09:17 PM
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
Posted 10 June 2013 - 05:05 AM
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
Posted 10 June 2013 - 05:24 AM
ZagKalidor, on 10 June 2013 - 05:05 AM, said:
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
Posted 10 June 2013 - 03:18 PM
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
Posted 10 June 2013 - 07:08 PM
Mikeemoo, on 10 June 2013 - 05:24 AM, said:
ZagKalidor, on 10 June 2013 - 05:05 AM, said:
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











