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

Can someone try to fix it?

Started by ViTALiTY, 10 August 2012 - 08:54 PM
ViTALiTY #1
Posted 10 August 2012 - 10:54 PM
Can you take look at this code for me, it gives me this error

http://pastebin.com/j3sMN7cB

sensors:33: attempt to concatenate nil and string

Here are some screenshots:

http://i45.tinypic.com/sbphjr.png
http://i46.tinypic.com/nybprm.png
http://i45.tinypic.com/242uelw.png

If someone could help, it would be great!
CharlesBroughton #2
Posted 10 August 2012 - 11:47 PM
Well, basically it means "unit" at that time was never assigned a value. I think the culprit is here:


if Tier == 1 then
unit = "BatBox"
elseif Tier == 2 then
unit = "MFE"
elseif Tier == 3 then
unit = "MFSU"
end

Perhaps you should have an "ELSE" to capture any other values, as it seems the value does not match any one being set here.
Pharap #3
Posted 11 August 2012 - 04:56 AM
Can you take look at this code for me, it gives me this error

http://pastebin.com/j3sMN7cB

sensors:33: attempt to concatenate nil and string

Basically it means you are trying to put a nil value into a string.

What Charles suggested was on the right track, something is being set to what it shouldn't be, but your culprit isn't unit, it's located at line 33, where you try to print the variables Energy and Max. Do what Charles suggested about checking for other conditions, but do it with Max and Energy instead(in this case you want to check max and energy aren't nil, and set them to zero or "error" if they are, so it doesn't cause the error.). Ultimately your issue is that what you are trying to read into Max and Energy aren't there, so they probably haven't been saved to the file properly.

Anyway, hope that helps.
ViTALiTY #4
Posted 11 August 2012 - 07:33 PM
Since im not that familiar with coding, could you give me the example of what i need to change in order ir to work?
Pharap #5
Posted 11 August 2012 - 08:30 PM
Since im not that familiar with coding, could you give me the example of what i need to change in order ir to work?

I'm guessing someone else wrote some of this code then?

Try using this:

term.clear()
term.setCursorPos(1,1)
Targets = sensors.getAvailableTargetsforProbe("right", "EUSensor", "EUStorage")
if #Targets ~= 0 then
  Reading = sensors.getSensorReadingAsDict("right", "EUSensor", Targets[1], "EUStorage")
  Max = Reading.maxStorage
  Energy = Reading.energy
  Tier = Reading.tier

  for k, v in pairs(Reading) do print(k, V) end
else
  Max = 0
  Energy = 0
  Tier = 1
end
if Tier == 1 then
unit = "BatBox"
elseif Tier == 2 then
unit = "MFE"
elseif Tier == 3 then
unit = "MFSU"
else
unit= "error"
end
if Energy == nil then
Energy = "error"
end
if Max == nil then
Max = "error"
end
while true do
sleep(0)
term.clear()
term.setCursorPos(1,1)
write("================UTILITIES=================")
term.setCursorPos(1,2)
write("Time	  : "..textutils.formatTime(os.time(),true))
term.setCursorPos(1,4)
write("===============STORAGE UNIT===============")
term.setCursorPos(1,5)
write("Energy   : "..Energy.."/"..Max.." ")
term.setCursorPos(1,6)
write("Tier	  : "..unit.." ")
end

Now if there's a problem with the file reading, the computer will write error where energy,max and unit should be.
As for any errors with the sensor-related code, I can't help with that unless I know what the functions of it are.
ViTALiTY #6
Posted 11 August 2012 - 08:38 PM
Yes, this code is not mine, i dont claim it as mine. I just need help getting it to work.
ViTALiTY #7
Posted 11 August 2012 - 08:44 PM
I tried the code and this is what i get:

http://i46.tinypic.com/24wf3wi.png
Cranium #8
Posted 12 August 2012 - 12:40 AM
Well that's better then. That means it's probably something with the CcSensor not communicating.
Pharap #9
Posted 12 August 2012 - 03:25 AM
I tried the code and this is what i get:

http://i46.tinypic.com/24wf3wi.png

Ok, I'm not good with sensors, so I'm going to suggest a few things that may not work (since I've never even looked at sensor code, let alone used one)

try replacing

Reading = sensors.getSensorReadingAsDict("right", "EUSensor", Targets[1], "EUStorage")
with

Reading = sensors.getSensorReadingAsDict("right", "EUSensor", Targets, "EUStorage")
or possibly

Reading = sensors.getSensorReadingAsDict("right", "EUSensor", Targets[0], "EUStorage")
to see if these work.
If not, I'll have to read into sensors.
ViTALiTY #10
Posted 12 August 2012 - 02:34 PM
Nope, not working.