Jump to content




Auto Wrap


8 replies to this topic

#1 plazter

  • Members
  • 134 posts

Posted 27 March 2016 - 05:11 AM

Hey Pros!
So a buddy and i, have been playing around for an auto wrapper for turbines and monitors, but when we plug the monitor into the system, it gives us error: 36:attempt to call nill

Code:
Spoiler

Any help is appreciated! :)
//Plazter

EDIT: the "(b )/>" is done by the editor.. dno why we use "(b )"
EDIT 2#:
turbines = {peripheral.find("BigReactors-Turbine")}
monitors = {peripheral.find("monitor")}
for i=1, #monitors do
  monitors[i].clear()
  monitors[i].write("*")
end
print ("Amount of turbines found: "..table.getn(turbines).."\n")
for i = 1, #turbines do
		monitors[1].write(turbines[1].getActive())
end
Line 10: "monitors[1].write(turbines[1].getActive())
is returning a "attempt to call nill" error, really cant see where its going wrong :( (if you read before i edited the edited the edited version, we have some snipped out part in the code ingame, typed without thinking :P)

Edited by plazter, 27 March 2016 - 06:07 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 27 March 2016 - 05:22 AM

Well, if any non-monitor is directly next to your system, then your isMonitor() function will erroneously return true for that device... this'd lead to your loop down the bottom erroring out.

It looks like you're really after peripheral.find():

local monitors = {peripheral.find("monitor")}


#3 plazter

  • Members
  • 134 posts

Posted 27 March 2016 - 05:26 AM

View PostBomb Bloke, on 27 March 2016 - 05:22 AM, said:

Well, if any non-monitor is directly next to your system, then your isMonitor() function will erroneously return true for that device... this'd lead to your loop down the bottom erroring out.

It looks like you're really after peripheral.find():

local monitors = {peripheral.find("monitor")}

That worked, thanks bloke!

#4 plazter

  • Members
  • 134 posts

Posted 27 March 2016 - 05:51 AM

Ok, we changed a code for a bit.. and it now looks like this:
turbines = {peripheral.find("BigReactors-Turbine")}
monitors = {peripheral.find("monitor")}

for i=1, #monitors do
  monitors[i].clear()
  monitors[i].write("*")
end
print ("Amount of turbines found: "..table.getn(turbines).."\n")
for i = 1, #turbines do
	monitors[1].write(turbines[1].getActive())
end

That now gives us an attempt to call nill :/

Edited by plazter, 27 March 2016 - 05:54 AM.


#5 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 27 March 2016 - 05:54 AM

On your first line, you're missing a closing quote and closing brackets/parenthesis
turbines = { peripheral.find("BigReactors-Turbine") }


#6 plazter

  • Members
  • 134 posts

Posted 27 March 2016 - 05:55 AM

View PostDog, on 27 March 2016 - 05:54 AM, said:

On your first line, you're missing a closing quote and closing brackets/parenthesis
turbines = { peripheral.find("BigReactors-Turbine") }

just saw that, it was a typo :P, the error is still occuring.. line 10: Attempt to call nill

Edited by plazter, 27 March 2016 - 06:05 AM.


#7 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 27 March 2016 - 06:23 AM

monitors[1].write(turbines[1].getActive())
--#Should be
monitors[1].write(turbines[i].getActive())
At the same time, I would first make sure that such values exist.
if (turbines[i] and turbines[i].getActive) then
   monitors[1].write(turbines[i].getActive())
end
If nothing prints out then we know for a fact that you're for some reason not getting properly wrapped turbines, or that they don't have a .getActive method

#8 plazter

  • Members
  • 134 posts

Posted 27 March 2016 - 07:22 AM

View PostDragon53535, on 27 March 2016 - 06:23 AM, said:

monitors[1].write(turbines[1].getActive())
--#Should be
monitors[1].write(turbines[i].getActive())
At the same time, I would first make sure that such values exist.
if (turbines[i] and turbines[i].getActive) then
   monitors[1].write(turbines[i].getActive())
end
If nothing prints out then we know for a fact that you're for some reason not getting properly wrapped turbines, or that they don't have a .getActive method

we got it working, i had done the isActive ingame.. derp :>, and the if one u mention.. i like that idea :>

#9 COOLGAMETUBE

  • Members
  • 49 posts
  • LocationGermany

Posted 30 March 2016 - 10:58 AM

I included a service into my Framework:

/os/services/deviceMountService:
local e, param1, param2, param3, param4, param5 = os.pullEvent()
if e == "peripheral" or e == "peripheral_detach" then
if not WicowsTools.compareTables(
  devices.all,
  peripheral.getNames()) then
  shell.run("/os/boot/registerDevices", "--quiet")
  shell.run("/os/boot/openRednet", "--quiet")
end
end

/os/boot/registerDevices:
devices = {}
devices.all = {}
local ol = peripheral.getNames()
local opt = {...}
for i = 1, #ol do
local oside = ol[i]
local otype = peripheral.getType(oside)
if #opt > 0 and opt[1] == "--quiet" then else
  print("Found \""..otype.."\" at \""..oside.."\"")
end
if not devices[otype] then
  devices[otype] = {}
end
table.insert(devices["all"], oside)
table.insert(devices[otype], oside)
if #opt > 0 and opt[1] == "--quiet" then else
  sleep(0.05)
end
end

/os/boot/openRednet:
if devices["modem"] then
for i = 1, #devices.modem do
  local side = devices.modem[i]
  if side == "top" or side == "left" or side == "right" or side == "bottom" or side == "back" or side == "top" then
   rednet.open(side)
   local opt = {...}
   if #opt > 0 and opt[1] == "--quiet" then else
	print("Rednet is now open on side "..side)
	sleep(0.05)
   end
  end
end
end


I called this with the parallel API:
/os/boot/settupServices:
local services = {}
svl = fs.list("/os/services")
for i = 1, #svl do
table.insert(services, function() while true do shell.run("/os/services/"..svl[i]) end end)
end
local resume = function()
shell.setPath(".:/os/programs"..string.sub(shell.path(),2))
shell.run("cd", "/")
shell.run("/os/wicows/lockscreen/main")
end
parallel.waitForAll(resume, table.unpack(services))


EDIT: Before i forgot, i used functions of my WicowsTools-API!

Edited by COOLGAMETUBE, 30 March 2016 - 11:09 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users