Jump to content




Probleme with mfsu

help

24 replies to this topic

#1 magnasie

  • Members
  • 13 posts

Posted 23 October 2016 - 10: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 --'

#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 24 October 2016 - 12: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.

#3 apemanzilla

  • Members
  • 1,421 posts

Posted 24 October 2016 - 01:06 AM

You're short a few lines of code, are you sure that's the complete source?

Edited by apemanzilla, 24 October 2016 - 01:09 AM.


#4 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 09: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


#5 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 09:23 AM

The problem is the line:
stored = mfsu.getEUStored()


#6 Bomb Bloke

    Hobbyist Coder

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

Posted 24 October 2016 - 01: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.

#7 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 04:27 PM

when I try to use your suggest :/file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png
Posted Image
file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png
file:///E:/FTB/Direwolf20_1_5_2/minecraft/screenshots/2016-10-24_18.22.42.png

Sry the 2 last link is a fail, and I can't remove it (bug maybe) <_<

#8 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 04:32 PM

And the problem is, it's working with the other program :

View Postmagnasie, on 23 October 2016 - 10:23 PM, said:


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 by magnasie, 24 October 2016 - 04:34 PM.


#9 Gorzoid

  • Members
  • 44 posts

Posted 24 October 2016 - 06: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

#10 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 06:45 PM

I don't understand ... can you correct my code please ? :/
Posted Image
This is the configuration and this is the my pastebin for emiter:
http://pastebin.com/U2iUWrbA

#11 Larry84

  • Members
  • 51 posts
  • LocationItaly

Posted 24 October 2016 - 08:01 PM

So, the problem is that you're having an error? (sorry but I can't understand from previous posts)

#12 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 09:00 PM

View PostLarry84, on 24 October 2016 - 08:01 PM, said:

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 ^^

#13 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 October 2016 - 09: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?

#14 magnasie

  • Members
  • 13 posts

Posted 24 October 2016 - 10:04 PM

View PostKingofGamesYami, on 24 October 2016 - 09:10 PM, said:

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 by magnasie, 24 October 2016 - 10:04 PM.


#15 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 24 October 2016 - 10:57 PM

Is this the same world?

#16 magnasie

  • Members
  • 13 posts

Posted 25 October 2016 - 10:32 AM

View PostKingofGamesYami, on 24 October 2016 - 10:57 PM, said:

Is this the same world?

Not the same :/

#17 Larry84

  • Members
  • 51 posts
  • LocationItaly

Posted 25 October 2016 - 06:24 PM

Do you have openperipherals installed?

#18 magnasie

  • Members
  • 13 posts

Posted 25 October 2016 - 06: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 ?

#19 Larry84

  • Members
  • 51 posts
  • LocationItaly

Posted 25 October 2016 - 06:48 PM

I've tryed it, and it works just fine. I don't know what to say.

#20 magnasie

  • Members
  • 13 posts

Posted 25 October 2016 - 07:02 PM

ouch x) it's very bad for me x)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users