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

What Did I Break?

Started by LittleBlackA, 07 April 2014 - 09:03 AM
LittleBlackA #1
Posted 07 April 2014 - 11:03 AM
Hello, I think I broke Marikc0's Base Program here it is, I tried adding support for an extra monitor and a clock :D/>, I AM NEW TO LUA please do not judge my shi**y coding as I am new to LUA (Started today…) and sorry Marikc0 if this is a copyright thingo I was just trying to learn LUA, take it down if you must :P/>. Here is the pastebin link to my fail: http://pastebin.com/Uyxsu5Rc

Everything works except the actual monitors information:


As you can see I got the Progress Bar on the other monitor working:


If you can can someone fix it up and add support for more MFSU's. Or teach me as I am a nub. :P/>

I will struggle to upload images as I hit my download cap…

Thanks All!
LittleBlackA #2
Posted 07 April 2014 - 11:29 PM
Bump?? Please Help..
Cranium #3
Posted 07 April 2014 - 11:48 PM
Please be patient with your request. Don't bump your own topic, without useful info. Have you tried anything else on your own in the meantime? Any changes to the code you are using? We'd like to get some more info onw hat you need help with, but we're not likely to write the changes to the program for you, we'd more than likely teach you to make those changes.
LittleBlackA #4
Posted 07 April 2014 - 11:52 PM
I heavily edited the original, I know some of the coding is cluttered and unused but it should load because i stated the functions but it never gets to that point so it could be a loop or something, I dont know…
Cranium #5
Posted 08 April 2014 - 12:01 AM
Well, if you could, please post a copy of your code, and it would help if you point out the areas that aren't working as intended.
It would help us out a lot if you could do that, so we don't have to slog through a ton of code for you.
LittleBlackA #6
Posted 08 April 2014 - 12:07 AM
I have no idea where the issue is that is why i am posting it here…

Spoiler– ComputerCraft/OpenPeripherals Base Monitoring Program for MineCraft 1.6.4
– Made By Marikc0| Fixed/Edited By LittleBlackA
– Optimized For FTB Monster Pack: www.feed-the-beast.com/‎
– Thanks: LittleBlackA, Marikc0, Toxify89, Notch, Fogger, @EsperNet: #OpenMods, #computercraft @Freenode: #lua

– The color palette. You can add more.
local palette = {["white"] = 1, ["orange"] = 2, ["magenta"] = 4, ["lightBlue"] = 8, ["yellow"] = 16,
["lime"] = 32, ["pink"] = 64, ["gray"] = 128, ["lightGray"] = 256, ["cyan"] = 512, ["purple"] = 1024,
["blue"] = 2048, ["brown"] = 4096, ["green"] = 8192, ["red"] = 16384, ["black"] = 32768}

– *** CONFIG SECTION **
– MONITORS (the only required config change)
local left = "monitor_0" – first main display monitor
local right = "monitor_1" – second main display monitor
local top = "monitor_2" – auxiliary monitor for total power/capacity reading
– VARIOUS
local activeMsg, inactiveMsg, pendingMsg = "USING", "INACT", "PENDI"
local textSize = 1 – increments of 0.5
local isGPS = true – should we look for and display a nearby GPS?
– MACHINE and PERIPHERAL NAMES –
– Use the same # of characters for each so that formatting is aligned
local name_comp = "Compressor" – compressor
local name_furnace = "Electric Furnace" – electric furnace
local name_ext = "Extractor" – extractor
local name_mace = "Macerator" – macerator
local name_washer = "Ore Washer" – ore washer
local name_centrifuge = "Thermal Centrifuge" – thermal centrifuge
local name_former = "Metal Former" – metal former
local name_recycler = "Recycler" – recycler
local name_canning = "Canning Machine" – canning machine
– Name these whatever you wish, but it may not fit or alter alignment of other items
local name_mfsu = "MFSU"
local name_cesu = "CESU"
– COLORS
local hc = palette.lightBlue – default heading color
local tc = palette.white – default text color
local color_reading = palette.lime – power readings for example
local color_inactive = palette.gray – inactive reading for machines
local color_active = palette.red – active reading for machines
local color_machines = palette.orange – machine names
local color_ores = palette.pink – ore name color
– TEXT POSITIONS
local pwrX_Reading = 20 – X pos to display power readings
local machineDisplayXPos = 6 – X pos to start displaying machines
local offsetPos = 2 – left margin offset for text
local mStatusPos = 25
local orePos = 35
– SPECIAL CHARACTERS
local separator = " | "
local spacer = " : "
———————————————–

local pversion = "1.3.5.1b/Edit By LittleBlackA"

local waitTime = {9,13}
local timer = {0,0,0,0,0,0,0,0,0,0,0}
local supported_Power = {"mfsu","cesu","mfe","batbox"}
local supported_Machines = {"macerator","furnace","orewashing","thermalcentrifuge", "extractor",
"compressor", "canning", "recycler", "metalformer"}
local sleepAmt = 0.2
local numFormat = 1 – don't use it (yet) for multiple formatting types
– MACHINE SLOTS –
local ic2ItemUsed = 7 – input slot for most ic2 machines
local ic2ItemCreated = 2 – output slot for most ic2 machines
local oreWashItemUsed = 9 – input slot for orewasher
local thermCentrItemUsed = 9 – input slot for thermal centrifuge

– Load API —
if fs.exists("marik") then shell.run("rm marik") end
print [[ Updating API -Should Be Under 5 Seconds…
If it is over 5 seconds; either you have no internet connection or HTTPS API is not on/working]]
shell.run("pastebin get Th8tne6p marik")
print("Downloaded…Now loading :D/> ")
os.loadAPI("marik")
—————

term.clear()
print [[
——————————
Base controller 1.3.5.1b
——————————
Edit By LittleBlackA
Changelog:
Changed The Names Of Text To Make It Easier.
Fixed Some Bugs.
Implemented Extra Monitor To Display EU (Will Work On MJ/RF Soon)
]]
print("Starting Up Base Controls!")
print("5")
print("4")
print("3")
print("2")
print("1")
print("Enjoy! Made By Marikc0| Fixed By LittleBlackA")
machines = peripheral.getNames() – load a list of peripherals into a table
table.sort(machines) – so it displays in non-random manner

n,count = marik.numOfMachines()
print("Total peripherals detected: " .. count)
print("Power storage devices: " .. n)
print("Checking peripheral connections…")

– Monitors
local mon = peripheral.wrap(left)
local mon2 = peripheral.wrap(right)
local mon3 = peripheral.wrap(top)
mon.clear()
mon2.clear()
mon.setTextScale(textSize)
mon2.setTextScale(textSize)

– MONITOR 1 x,y Positions
local machinesInfoCol = 6 – machines info HEADING
local GPS_x = 25 – right side GPS info
local GPS_y = 58

– MONITOR 2 x,y Positions
local tankPosStart = 1 – to replace the rest of these

– MONITOR 1 - Write lines that won't be cleared
marik.cString(offsetPos, 1, hc, left, "– Main Power –")
marik.cString(offsetPos, machinesInfoCol, hc, left, "– Machines Info –")

– MONITOR 2 - Write lines that won't be cleared
marik.cString(offsetPos, 1, hc, right, "– RailCraft Tank Information –")


function dispAE()

– AE TERMINAL (not working yet)
mon2.setTextColor(tc)
mon2.setCursorPos(offsetPos,aeCraftCol)

beingCrafted = aeController.getJobList()
if beingCrafted.name ~= nil then
timer[1] = os.clock()
mon2.clearLine()
mon2.write("Currently Crafting: " .. beingCrafted.name)
elseif beingCrafted.name == nil then
mon2.clearLine()
mon2.write("Currently Crafting: Nothing")
else
mon2.clearLine()
mon2.write("Currently Crafting: Unknown")
end
end

function pFormat(pName)
– Renames peripherals for formatting purposes

if string.find(pName, "compressor") then
pName = name_comp
elseif string.find(pName, "electric_furnace") then
pName = name_furnace
elseif string.find(pName, "extractor") then
pName = name_ext
elseif string.find(pName, "macerator") then
pName = name_mace
elseif string.find(pName, "orewashing") then
pName = name_washer
elseif string.find(pName, "thermalcentrifuge") then
pName = name_centrifuge
elseif string.find(pName, "canning") then
pName = name_canning
elseif string.find(pName, "recycler") then
pName = name_recycler
elseif string.find(pName, "former") then
pName = name_former
elseif string.find(pName, "mfsu") then
pName = name_mfsu
elseif string.find(pName, "cesu") then
pName = name_cesu
end
return pName
end

function dispTanks()
mon.setCursorPos(offsetPos, 1)
mon2.setCursorPos(offsetPos,1)

for i=1, #machines do
– RC Tanks ——————————————–
if string.find(machines, "rcirontankvalvetile")
or string.find(machines, "rcsteeltankvalvetile") then

if peripheral.isPresent(machines) then
periph = peripheral.wrap(machines)

fluidRaw, fluidName, fluidAmount, fluidCapacity, fluidID = marik.getTank(periph)

if fluidName == nil then
– does not display empty tanks
elseif fluidName ~= nil then
mon2.setTextColor(tc)
x,y = mon2.getCursorPos()
mon2.setCursorPos(offsetPos, (y+1))
mon2.clearLine()
– marik.cString(offsetPos,(y+1), tc, right, " ")
mon2.write("Tank (" .. marik.comma(fluidName) .. ") : " .. marik.comma(fluidAmount) .. " / " .. marik.comma(fluidCapacity) .. " mb (" .. marik.getBuckets(fluidAmount) .. " buckets)")
end
end
end
end
end

function dispPower()

for i=1, #machines do
– IC2 Power ——————————————-
for s=1, #supported_Power do
if string.find(machines, supported_Power) then

periph = peripheral.wrap(machines)
local storedEU = periph.getEUStored()
local capacity = periph.getEUCapacity()

– modify these later for multiple storage peripherals
local totalStorage = storedEU
local totalCapacity = capacity

marik.appendString(left, tc, "Total EU " .. separator, true, offsetPos, 2)
marik.appendString(left, color_reading, (marik.comma(totalStorage)), false, pwrX_Reading, 2)

marik.appendString(left, tc, "Total Capacity " .. separator, true, offsetPos, 3)
marik.appendString(left, color_reading, (marik.comma(totalCapacity)), false, pwrX_Reading, 3)

marik.appendString(left, tc, pFormat(machines) .. " Storage " .. separator, true, offsetPos, 4)
marik.appendString(left, color_reading, (marik.comma(storedEU)), false, pwrX_Reading, 4)

end
end
end
end


function dispIC2()

machineDispStart = machineDisplayXPos – screen start positon

for i=1, #machines do
– IC2 Machines —————————————–
local m
for m=1, #supported_Machines do
– check if the machine is a supported machine
if string.find(machines, supported_Machines[m]) then

– check if the peripheral is connected
– if peripheral.isPresent(machines) then
periph = peripheral.wrap(machines)

– determine what slot to use for the machines' input
if string.find(machines, "thermalcentrifuge") then itemStackUsed = periph.getStackInSlot(thermCentrItemUsed)
elseif string.find(machines, "orewashing") then itemStackUsed = periph.getStackInSlot(oreWashItemUsed)
else itemStackUsed = periph.getStackInSlot(ic2ItemUsed)
end

machineDispStart = machineDispStart + 1 – move this down?

– if there's something in the input slot
if itemStackUsed ~= nil then
itemName = marik.itemRename(itemStackUsed.name)
timer[2] = os.clock()

– display machine, active message and itemName
marik.appendString(left, color_ores, itemName, true, orePos, machineDispStart) – append the itemName
str = (pFormat(peripheral.getType(machines)))
marik.appendString(left, tc, str, false, offsetPos, machineDispStart) – append the [ ] that contains the itemName
marik.appendString(left, color_active, activeMsg, false, 11, machineDispStart) – append the activeMsg

– if there is nothing in the input slot
elseif itemStackUsed == nil then
if os.clock() - timer[2] > waitTime[1] then – clear the message only if it has been waitTime[1] seconds

–display machine and inactive message
marik.appendString(left, color_inactive, inactiveMsg, true, mStatusPos, machineDispStart) – append INACTIVE
str = (pFormat(peripheral.getType(machines)))
marik.appendString(left, tc, str, false, offsetPos, machineDispStart) – append the [ ] that contains the itemName

end

else
– marik.appendString(left, color_active, "***TEST CASE***", false, offsetPos, machineDispStart)
end
– end
end
end
end
end

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 = peripheral.wrap("top")
local mfsu = findPeripheral("mfsu")
local batbox = findPeripheral("batbox")

if not m then
error("Cannot find monitor attached to this computer -How do you forget the monitor?-", 0)
end

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

m.setTextScale(1)

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.pink)
m.setCursorPos(2, 8)
m.write(string.rep(" ", w-2))
m.setBackgroundColour(colours.purple)
m.setCursorPos(2, 8)
m.write(string.rep(" ", p))
m.setBackgroundColour(colours.black)

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

dispTanks()
dispPower()
dispIC2()
displayTime()

– Loop Start
while true do

mon.setTextColor(tc)
if marik.GPSinfo() then
mon.setCursorPos(GPS_y, GPS_x)
mon.write("GPS: Online")
else
mon.setCursorPos(GPS_y, GPS_x)
mon.write("GPS: Offline")
end

sleep(sleepAmt)

end

Sorry If I am noob…
Edited on 07 April 2014 - 10:08 PM
LittleBlackA #7
Posted 08 April 2014 - 12:20 AM
Tbh i will recode by scratch as it is easier… Sorry for the in-convienience

Close thread is you want.
LittleBlackA #8
Posted 08 April 2014 - 02:28 AM
I got it just need to find a way to input the Time…