This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
magnasie's profile picture

Probleme with mfsu

Started by magnasie, 23 October 2016 - 09:23 PM
magnasie #1
Posted 23 October 2016 - 11:23 PM
Hello everybody !
I'm trying to make my first "real" program, but I'm stuck.
I want to take the energy of my MFSU and send it to an other computer, but I can't take the information of energy in MFSU.
I look on lot of other program but don't know … help me please.

My program :

local modem = peripheral.wrap("right")
local mfsu = peripheral.wrap("left")
while true do
if not mfsu then
  error("Cannot find mfsu attached to this computer", 0)
end
if not modem then
  error("Cannot find modem attached to this computer", 0)
end
while true do
  local stored = 0
	stored = mfsu.getEUStored()
modem.transmit(7, 1, stored)
sleep(1)
end
end

My error:

mfsu:16:  attempt to call nil

and my inspiration:


local function padLeft(str, w)
  return string.rep(" ", w - #str) .. str
end

local function findPeripheral(_type)
  for _,name in pairs(peripheral.getNames()) do
	if peripheral.getType(name) == _type then
	  return peripheral.wrap(name)
	end
  end
end

local m = findPeripheral("monitor")
local mfsu = findPeripheral("mfsu")
local batbox = findPeripheral("batbox")

if not m then
  error("Cannot find monitor attached to this computer", 0)
end

if not mfsu and not batbox then
  error("Cannot find mfsu attached to this computer", 0)
end

m.setTextScale(0.5)

local w, h = m.getSize()
local total = 0

if mfsu then
  total = mfsu.getEUCapacity()
elseif batbox then
  total = batbox.getCapacity()
end
os.startTimer(1)

while true do
  local stored = 0
  if mfsu then
	stored = mfsu.getEUStored()
  elseif batbox then
	stored = batbox.getStored()
  end

  m.clear()
  m.setCursorPos(1, 2)
  m.setTextColour(colours.orange)
  m.write("Energy:")
  m.setTextColour(colours.white)
  m.write(padLeft(tostring(stored), w - 7))

  m.setCursorPos(1, 4)
  m.setTextColour(colours.orange)
  m.write("Total:")
  m.setTextColour(colours.white)
  m.write(padLeft(tostring(total), w - 6))

  local p = (w-2) * stored / total

  m.setBackgroundColour(colours.lightGrey)
  m.setCursorPos(2, 8)
  m.write(string.rep(" ", w-2))
  m.setBackgroundColour(colours.grey)
  m.setCursorPos(2, 8)
  m.write(string.rep(" ", p))
  m.setBackgroundColour(colours.black)

  os.pullEvent("timer")
  os.startTimer(1)
end

Please, where is the problem ? Thank you a lot !

PS : Sorry for my really bad english –'
Dog #2
Posted 24 October 2016 - 01:30 AM
Is this the *exact* code you are running? I ask because the code is only 16 lines long and wouldn't be able to produce that error. Also, you don't need the outer (first) while loop - it's unnecessary.
apemanzilla #3
Posted 24 October 2016 - 02:06 AM
You're short a few lines of code, are you sure that's the complete source?
Edited on 24 October 2016 - 12:09 AM
magnasie #4
Posted 24 October 2016 - 10:22 AM
Oh sorry, some "return ?" was away –'

local modem = peripheral.wrap("right")
local mfsu = peripheral.wrap("left")

while true do

if not mfsu then
  error("Cannot find mfsu attached to this computer", 0)
end

if not modem then
  error("Cannot find modem attached to this computer", 0)
end

while true do
  local stored = 0
    stored = mfsu.getEUStored()
modem.transmit(7, 1, stored)
sleep(1)
end
end
magnasie #5
Posted 24 October 2016 - 10:23 AM
The problem is the line:

stored = mfsu.getEUStored()
Bomb Bloke #6
Posted 24 October 2016 - 02:40 PM
That suggests that your MFSU is recognised as a peripheral, but doesn't offer a "getEUStored" function.

You may be able to use this to see what functions it does offer.
magnasie #7
Posted 24 October 2016 - 05:27 PM
when I try to use your suggest :/[img]file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png[/img]

[img]file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png[/img]
[img]file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png[/img]

Sry the 2 last link is a fail, and I can't remove it (bug maybe) <_</>
magnasie #8
Posted 24 October 2016 - 05:32 PM
And the problem is, it's working with the other program :
and my inspiration:


local function padLeft(str, w)
  return string.rep(" ", w - #str) .. str
end

local function findPeripheral(_type)
  for _,name in pairs(peripheral.getNames()) do
	if peripheral.getType(name) == _type then
	  return peripheral.wrap(name)
	end
  end
end

local m = findPeripheral("monitor")
local mfsu = findPeripheral("mfsu")
local batbox = findPeripheral("batbox")

if not m then
  error("Cannot find monitor attached to this computer", 0)
end

if not mfsu and not batbox then
  error("Cannot find mfsu attached to this computer", 0)
end

m.setTextScale(0.5)

local w, h = m.getSize()
local total = 0

if mfsu then
  total = mfsu.getEUCapacity()
elseif batbox then
  total = batbox.getCapacity()
end
os.startTimer(1)

while true do
  local stored = 0
  if mfsu then
	stored = mfsu.getEUStored()
  elseif batbox then
	stored = batbox.getStored()
  end

  m.clear()
  m.setCursorPos(1, 2)
  m.setTextColour(colours.orange)
  m.write("Energy:")
  m.setTextColour(colours.white)
  m.write(padLeft(tostring(stored), w - 7))

  m.setCursorPos(1, 4)
  m.setTextColour(colours.orange)
  m.write("Total:")
  m.setTextColour(colours.white)
  m.write(padLeft(tostring(total), w - 6))

  local p = (w-2) * stored / total

  m.setBackgroundColour(colours.lightGrey)
  m.setCursorPos(2, 8)
  m.write(string.rep(" ", w-2))
  m.setBackgroundColour(colours.grey)
  m.setCursorPos(2, 8)
  m.write(string.rep(" ", p))
  m.setBackgroundColour(colours.black)

  os.pullEvent("timer")
  os.startTimer(1)
end
Edited on 24 October 2016 - 03:34 PM
Gorzoid #9
Posted 24 October 2016 - 07:36 PM
You probably mixed up left and right. It's your left when looking at screen not the computers iirc, just use peripheral.find instead
magnasie #10
Posted 24 October 2016 - 07:45 PM
I don't understand … can you correct my code please ? :/

This is the configuration and this is the my pastebin for emiter:
http://pastebin.com/U2iUWrbA
Larry84 #11
Posted 24 October 2016 - 09:01 PM
So, the problem is that you're having an error? (sorry but I can't understand from previous posts)
magnasie #12
Posted 24 October 2016 - 10:00 PM
So, the problem is that you're having an error? (sorry but I can't understand from previous posts)
Yes, with the line "stored = mfsu.getEUStored()"

mfsu:16:  attempt to call nil

But I copy this line to another pastebin (you can find it at top) and it's working.

The photo is just the setup of computer ^^
KingofGamesYami #13
Posted 24 October 2016 - 10:10 PM
It looks like it should be correct. However, what happens if you use the findPeripheral function specified in the other script to wrap it instead?
magnasie #14
Posted 24 October 2016 - 11:04 PM
It looks like it should be correct. However, what happens if you use the findPeripheral function specified in the other script to wrap it instead?

It's said "Connot find mfsu attached to this computer", but the mfsu is here x) the same in solo with an other computer and an other mfsu …

PS: new code:

local modem = peripheral.wrap("right")

local function padLeft(str, w)
  return string.rep(" ", w - #str) .. str
end

local function findPeripheral(_type)
  for _,name in pairs(peripheral.getNames()) do
	    if peripheral.getType(name) == _type then
		  return peripheral.wrap(name)
	    end
  end
end

local mfsu = findPeripheral("mfsu")

while true do

if not mfsu then
  error("Cannot find mfsu attached to this computer", 0)
end

if not modem then
  error("Cannot find modem attached to this computer", 0)
end

while true do
  local stored = 0
    stored = mfsu.getEUStored()
modem.transmit(7, 1, stored)
sleep(1)
end
end
Edited on 24 October 2016 - 09:04 PM
KingofGamesYami #15
Posted 24 October 2016 - 11:57 PM
Is this the same world?
magnasie #16
Posted 25 October 2016 - 11:32 AM
Is this the same world?

Not the same :/
Larry84 #17
Posted 25 October 2016 - 07:24 PM
Do you have openperipherals installed?
magnasie #18
Posted 25 October 2016 - 07:36 PM
yes, and the other API is working on my two worlds, with the same mfsu. I don't know why my API is not working ..
Can you try the program on your computer ?
Larry84 #19
Posted 25 October 2016 - 07:48 PM
I've tryed it, and it works just fine. I don't know what to say.
magnasie #20
Posted 25 October 2016 - 08:02 PM
ouch x) it's very bad for me x)
Larry84 #21
Posted 25 October 2016 - 08:13 PM
Try to do these steps: first of all open your computer near the mfsu, then type in "lua". After that type
mfsu=peripheral.wrap("left")
and then
mfsu.getEUStored()

Let's see what it does.
magnasie #22
Posted 25 October 2016 - 08:33 PM
I finally find a solution !!
Try to do these steps: first of all open your computer near the mfsu, then type in "lua". After that type
mfsu=peripheral.wrap("left")
and then
mfsu.getEUStored()

Let's see what it does.

I try what you say but it was the same, so i replace mfsu.getEUStored() by mfsu.getStored() and it's working ^^' (for the moment), I can work now ! ^^ Thanks everyone !
Larry84 #23
Posted 25 October 2016 - 08:51 PM
I finally find a solution !!

I try what you say but it was the same, so i replace mfsu.getEUStored() by mfsu.getStored() and it's working ^^' (for the moment), I can work now ! ^^ Thanks everyone !

Really? It isn't a method aviable for mfsus I think…
But if it works, well, great! I'm glad to hear that you've resolved the problem. You're welcome!
magnasie #24
Posted 25 October 2016 - 08:53 PM
I finally find a solution !!

I try what you say but it was the same, so i replace mfsu.getEUStored() by mfsu.getStored() and it's working ^^' (for the moment), I can work now ! ^^ Thanks everyone !

Really? It isn't a method aviable for mfsus I think…
But if it works, well, great! I'm glad to hear that you've resolved the problem. You're welcome!

It's possibly (not sure) because i'm on 1.5.2 (I prefer this DireWolf pack ^^' ) and the mfsu was possibly not update :/
Larry84 #25
Posted 25 October 2016 - 09:40 PM
:huh:/> Yeah, I think that probably that's the matter.