Posted 21 April 2013 - 10:12 AM
Spoiler
os.loadAPI("ocs/apis/sensor") --load OpenCCSensors sensor API
left = sensor.wrap("left") --wrap the sensor
m = peripheral.wrap("top") --wrap the monitor
term.redirect(m) --redirect output to monitor
local headerText = "Shop v1" --store header text in variable
function fetchTargets() --define new function "fetchTargets()"
local targets = sensor.call("left","getTargets") --fill table "targets" with getTargets from sensor
end --close the function
function render() --define new function "render()"
if targets then --if the table "targets" is not nil then...
for name, basicDetails in pairs(targets) do --for lenght of name and basicDetails in table targets do
print("Entity: "..name.." "..textutils.serialize(basicDetails.position)) --print the name of entity, print serialized position of the entity
end --end for loop
end --end if
end --end function
function header() --define new function "header()"
x,y = term.getSize() --gets size of terminal(in this case monitor on top)
for i = 1,x do --for 1 to value of x do
term.write("-") --write "-"
end --end loop
term.write("\n") --new line
term.write("\n") --new line
for i = 1,x do --for 1 to value of x do
term.write("-")
end
term.setCursorPos(x/2-#headerText/2, 2) --sets the cursor to x/2 - lenght of headerText/2 char. of 2nd line
term.write(headerText) --writes the text to the screen
term.setCursorPos(1,4) --sets the cursor to 1st char. of 4th line
end
function redraw() --define new function "redraw()"
term.clear() --clears the terminal
term.setCursorPos(1,1) --sets the cursor to 1st char. of 1st line
fetchTargets() --calls the fetchTargets() function
header() --calls the header() function
render() --calls the render() function
end
while 1 == 1 do --infinite loop (1 is always equal to 1)
redraw() --calls the redraw() function
sleep(1) --sleeps for 1 second
end --closes the loop
term.restore() --this will be usefull if I add some variable to end the loop (or use break)
—————————————————–
______________Shop v1
—————————————————–
//replace _ with [space]
and nothing else… When I was testing the sensor I had this:
Spoiler
os.loadAPI("ocs/apis/sensor")
m = peripheral.wrap("top")
left = sensor.wrap("left")
term.redirect(m)
while true do
term.clear()
term.setCursorPos(1,1)
local targets = sensor.call("left","getTargets")
if targets then
for name, basicDetails in pairs(targets) do
print("Entity: "..name.." "..textutils.serialize(basicDetails.position))
print("-----")
end
end
sleep(1)
end
Entity: D3add3d {X=1,Y=1,Z=1}
—–
Entity: NeoRazorX {X=2,Y=1,Z=1}
—–
So… my question is why is it not showing the entity thing?