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

Hello Guys

Started by Olalaland, 12 March 2014 - 05:08 PM
Olalaland #1
Posted 12 March 2014 - 06:08 PM
Can anyone of u guys convert this script http://pastebin.com/ycZaFpF0#
to the actually openperipherals code?
CometWolf #2
Posted 12 March 2014 - 06:45 PM
That is actual openP code, just a little outdated i believe, but regardless this is not what Ask a pro is for. We are not supposed to do the work for you, merely help you do it yourself.
Olalaland #3
Posted 12 March 2014 - 07:08 PM
mhh i cant do this thats why i ask for some help
CometWolf #4
Posted 13 March 2014 - 05:26 AM
Why "can't" you do this, what's stopping you from learning?
Olalaland #5
Posted 13 March 2014 - 05:58 PM
Mhh i need this script in a different version if i have one with the new variables i can learn from it and change it to a script what i need
CometWolf #6
Posted 13 March 2014 - 06:22 PM
Using this
http://www.dnacraft.info/open.info/web/app.php/openperipheral/documentation
Or the included docs program, will be easier for both you and anyone who would take on your request.
Olalaland #7
Posted 13 March 2014 - 06:31 PM
can u help me maybe to get an funktion to autodetect mfsu's and thermal expansions cells that is what i need because i dont want to add all mfsu's manualy to this script
Olalaland #8
Posted 13 March 2014 - 08:09 PM
Mhh i tried to convert the codes but its not working
CometWolf #9
Posted 13 March 2014 - 08:12 PM
Make up your mind!
set up a table for each peripheral type, then
loop the strings in the table returned by peripheral.getNames()
http://computercraft...pheral.getNames
through peripheral.getType()
http://computercraft...ipheral.getType
and use string.match() on the result, matching whatever peripheral you're looking for and adding it to the respective table if it's a match
http://lua-users.org...LibraryTutorial


local tMfsu = {} --create table for peripherals
for side in pairs(peripheral.getNames()) do --loop the table returned by getNames
  local perip = peripheral.getType(side) --get the type of peripheral
  if perip:match"mfsu" then --syntactic sugar way of writing string.match(perip,"mfsu")
	tMfsu[#tMfsu+1] = peripheral.wrap(side) -- since it's a match, we wrap it to the table
  end
end

Hell, the code you posted even has a function that already does this, except it dosen't handle wired peripherals.

Mhh i tried to convert the codes but its not working
I can't help, unless you tell me what "its not working" means. Does it error, does it not behave as expected, what?
Edited on 13 March 2014 - 07:15 PM
Olalaland #10
Posted 13 March 2014 - 08:13 PM
I mean this code http://pastebin.com/ycZaFpF0#

I tried it but i cant convert this
Anavrins #11
Posted 13 March 2014 - 09:03 PM
Not sure what you mean by "convert", can you elaborate?
Edited on 13 March 2014 - 08:03 PM
Olalaland #12
Posted 13 March 2014 - 09:06 PM
i have minecraft 1.6.4 with up to date open peripheral and this is for 1.5.2
Edited on 13 March 2014 - 08:07 PM
Lyqyd #13
Posted 13 March 2014 - 09:21 PM
Threads merged.
Olalaland #14
Posted 13 March 2014 - 09:51 PM
Is that the right way?

    --################CONFIG########################
	
    --boolean props to control use
    ic2 = true
    mj = true
	
    --Point in which to begin charging (1 - 99)
    chargePercent = 25
	
    --Configure storage devices
    --List storage (names received from wired modem) in these tables
    --If Auto-detection is enabled these tables can be left blank
    ic2Storage = {
		    "batbox_0"	
    }
    mjStorage = {
		  
    }
    --Auto-detect other storage on network?
    detection = true
	
    --Configure energy Generation.
    --Each item needs the type, direction bundle is attached and wire color
    --["type"]["direction"]["color"]
    generators = {
		    {
				    ["type"] = "mj",
				    ["direction"] = "bottom",
				    ["color"] = 4
		    },
		    {
				    ["type"] = "eu",
				    ["direction"] = "bottom",
				    ["color"] = 1
		    }
    }
	
    --###########END OF CONFIG#######################
	
    local tMfsu = {} --create table for peripherals
	    for side in pairs(peripheral.getNames()) do --loop the table returned by getNames
	    local perip = peripheral.getType(side) --get the type of peripheral
	    if perip:match"mfsu" then --syntactic sugar way of writing string.match(perip,"mfsu")
		   tMfsu[#tMfsu+1] = peripheral.wrap(side) -- since it's a match, we wrap it to the table
	    end
    end

	
    local function getStorage()
		    maxEU = 0
		    maxMJ= 0
		    --Grab max storage
		    if(ic2) then
				    for key,value in ipairs(ic2Storage) do
						    if(net.isPresentRemote(value)) then
								    maxEU = maxEU + net.callRemote(value,"getEUCapacity")
						    else
								    ic2Storage[key] = nil
						    end
				    end
		    end
		    if(mj) then
				    for key,value in ipairs(mjStorage) do
						    if(net.isPresentRemote(value)) then
								    maxMJ = maxMJ + net.callRemote(value,"getMaxEnergyStored")
						    else
								    mjStorage[key] = nil
						    end
				    end
		    end
    end
	
    local function findStorage()
		    local added = false
		    local new = true
		    if (mj) then
				    for i, remote in ipairs(net.getNamesRemote()) do
						    if(string.find(string.lower(remote),"redstone_energy_cell")) then
								    for key, value in ipairs(mjStorage) do
										    if (remote == value) then
												    new = false
										    end
								    end
								    if (new) then
										    table.insert(mjStorage, remote)
										    added = true
								    else
										    new = true
								    end
						    end
				    end
		    end
	
		    if (ic2) then
				    for i, remote in ipairs(net.getNamesRemote()) do
						    if(string.find(string.lower(remote), "batbox")) then
								    for key, value in ipairs(ic2Storage) do
										    if (remote == value) then
												    new = false
										    end
								    end
								    if (new) then
										    table.insert(ic2Storage, remote)
										    added = true
								    else
										    new = true
								    end
						    end
				    end
		    end
		    return added
    end
	
    local function setGeneration(strType, boolean, list)
		    local redstoneValue = {}
	
		    for key, value in pairs(list) do
				    if (value["type"] == strType) then
						    if(redstoneValue[value["direction"]] == nil)then
								    redstoneValue[value["direction"]] = redstone.getBundledOutput(value["direction"])
						    end
						    if (boolean) then
								    if (not colors.test(redstoneValue[value["direction"]],value["color"])) then
										    redstoneValue[value["direction"]] = redstoneValue[value["direction"]] + value["color"]
								    end
						    else
								    if (colors.test(redstoneValue[value["direction"]],value["color"])) then
										    redstoneValue[value["direction"]] = redstoneValue[value["direction"]] - value["color"]
								    end
						    end
				    end
		    end
		    -- Set redstone bundle
		    for key, value in pairs(redstoneValue) do
				    redstone.setBundledOutput(key, value)
		    end
    end
    local function int()
		    --Check for monitor
		    if(findLocalDevice("monitor")) then
				    term.clear()
				    term.write("monitor connected")
				    term.redirect(peripheral.wrap(findLocalDevice("monitor")))
		    end
	
		    --Prepare the screen
		    term.clear()
		    term.setCursorPos(1,1)
		    term.write("Power Management")
		    term.setCursorPos(1,2)
		    term.write("EU = NA")
		    term.setCursorPos(1,3)
		    term.write("0/0")
		    term.setCursorPos(1,4)
		    term.write("MJ = NA")
		    term.setCursorPos(1,5)
		    term.write("0/0")
		    term.setCursorPos(1,6)
	
		    if(not (ic2 or mj))then
				    term.write("Please choose sources in the config")
				    shell.exit()
		    end
	
		    --Variables to storage amounts
		    storedEU = 0
		    maxEU = 0
		    storedMJ = 0
		    maxMJ = 0
		    euPercent = 0
		    mjPercent = 0
		    --Other Vars
		    bridge = nil
		    net = nil
	
		    --Find network
		    if (findLocalDevice("modem") == nil) then
				    term.write("Cannot find Network")
				    shell.exit()
		    else
				    net = peripheral.wrap(findLocalDevice("modem"))
		    end
	
		    if(detection) then
				    findStorage()
		    end
	
		    getStorage()
	
		    --Dectect Bridge
		    if (findLocalDevice("terminal_glasses_bridge")) then
				    bridge  = peripheral.wrap(findLocalDevice("terminal_glasses_bridge"))
		    end
		    if (bridge) then
		    --Prepare Glasses
				    bridge.clear()
				    bridge.addText(1,1,"Power Management",colors.gray)
				    euText = bridge.addText(1,10, "EU = NA", colors.gray)
				    bridge.addBox(3, 20, 100, 5, colors.gray, 100)
				    euBar = bridge.addBox(3, 20, 0, 5, colors.red, 100)
				    euBar.setZIndex(4)
				    mjText = bridge.addText(1,28, "MJ = NA", colors.gray)
				    bridge.addBox(3, 38, 100, 5, colors.gray, 100)
				    mjBar = bridge.addBox(3, 38, 0, 5, colors.red, 100)
				    mjBar.setZIndex(4)
		    end
    end
    local function main()
		    storedMJ = 0
		    storedEU = 0
		    if(ic2) then
				    --Get amount of stored EU
				    for key,value in ipairs(ic2Storage) do
						    if(net.isPresentRemote(value)) then
								    storedEU = storedEU + net.callRemote(value,"getEUStored")
						    else
								    getStorage()
						    end
				    end
		    end
		    if(mj) then
				    --Get amount of stored MJ
				    for key,value in ipairs(mjStorage) do
						    if(net.isPresentRemote(value)) then
								    storedMJ = storedMJ + net.callRemote(value,"getEnergyStored")
						    else
								    getStorage()
						    end
				    end
		    end
		    euPercent = math.floor((storedEU / maxEU) * 100)
		    mjPercent = math.floor((storedMJ / maxMJ) * 100)
		    --control status
		    if(ic2) then
				    if (euPercent < chargePercent) then
						    setGeneration("eu",true,generators)
				    elseif((euPercent >= 100) or (maxEU == 0))then
						    setGeneration("eu",false,generators)
				    end
				    --update screen
				    term.setCursorPos(1,2)
				    term.clearLine()
				    term.write("EU = " .. euPercent .. "%")
				    term.setCursorPos(1,3)
	
				    --quick fix for IC2 output buffer
				    if (storedEU > maxEU) then
						    storedEU = maxEU
				    end
	
				    term.write(storedEU .. "/" .. maxEU)
		    end
	
		    if (mj) then
				    if (mjPercent < chargePercent) then
						    setGeneration("mj",true, generators)
				    elseif((mjPercent >= 100) or (maxMJ == 0)) then
						    setGeneration("mj", false, generators)
				    end
	
				    term.setCursorPos(1,4)
				    term.clearLine()
				    term.write("MJ = " .. mjPercent .. "%")
				    term.setCursorPos(1,5)
				    term.write(math.floor(storedMJ) .. "/" .. maxMJ)
		    end
		    term.setCursorPos(1,6)
	
		    if(bridge) then
				    --paint glasses
				    if(ic2) then
						    euText.setText("EU = " .. euPercent .. "%")
						    euBar.setWidth(euPercent)
				    end
				    if(mj) then
						    mjText.setText("MJ = " .. mjPercent .. "%")
						    mjBar.setWidth(mjPercent)
				    end   
		    end
		    sleep(1)
    end
	
    local function eventListener()
		    sleep(0)
		    p1, p2 = os.pullEventRaw()
		    if p1 == "terminate" then
				    quit = true
		    end
    end
	
    local function autoDetect()
		    local found = findStorage()
		    if(found) then
				    getStorage()
		    end
    end
	
    quit = false
    int()
	
    while true do
		    parallel.waitForAny(eventListener, main)
	
		    if quit then
			    for i, value in pairs(rs.getSides()) do
						    rs.setBundledOutput(value, 0)
				    end
				    term.clear()
				    term.restore()
				    term.clear()
				    term.setCursorPos(1,1)
				    if (findLocalDevice("terminal_glasses_bridge")) then
						    peripheral.call(findLocalDevice("terminal_glasses_bridge"),"clear")
				    end
				    print("Terminated")
			    break
		    end
		    if(detection) then
				    autoDetect()
		    end
	
		    sleep(0)
    end

Anavrins #15
Posted 13 March 2014 - 09:52 PM
I've adjusted deprecated names and function to match the newer version.
http://pastebin.com/Ye2RgptD
CometWolf #16
Posted 13 March 2014 - 10:03 PM
The code i posted was just an example, not something you can copy and paste, and as such won't work. Looking over the code, i realize it already auto detects the things you want, so why do you need it again?
Olalaland #17
Posted 14 March 2014 - 10:31 AM
I've adjusted deprecated names and function to match the newer version.
http://pastebin.com/Ye2RgptD

Mhh thats also not work
Dosent find the mfsu or dosent reply the power that in the mfsu's

It works only if i type in manualy the mfsu or any other storage he dosent find automaticaly the peripherals

and he can only handle 1 storage
CometWolf #18
Posted 14 March 2014 - 10:51 AM
Best i can tell it should be able to detect energy storages on it's own. Provided you have all of them connected via rednet cables. Where are you entering them manually?

What's with all the people showing up with outdated openP progs lately? Why not ask the person who made it, to fix it?
theoriginalbit #19
Posted 14 March 2014 - 11:01 AM
What's with all the people showing up with outdated openP progs lately? Why not ask the person who made it, to fix it?
I've been wondering the same!
Olalaland #20
Posted 14 March 2014 - 11:03 AM
ahh ok i found the problem

a probleme on line 98
CometWolf #21
Posted 14 March 2014 - 11:14 AM
Nothing wrong with 98, it looks for the word batbox in all wire connected peripherals. openP names all ic2 storage units batbox, last i checked.
Olalaland #22
Posted 14 March 2014 - 11:18 AM
yes but i search for mfsu's

Mhh now i got the next prob i have installed projred transmission but the bundle cables dosent conect to the computer is that a bug?
CometWolf #23
Posted 14 March 2014 - 11:25 AM
pRed cables are not compatible with CC, only MFR cables are.
Olalaland #24
Posted 14 March 2014 - 11:30 AM
I saw it now it works all fine thxs so much guys

mhh but they dosent stop the redstone signal on full Load
theoriginalbit #25
Posted 14 March 2014 - 11:30 AM
openP names all ic2 storage units batbox, last i checked.
latest versions should be fine, we try everything we can to get/generate a useful name, but unfortunately sometimes with the way mods are coded that is difficult. if you're interested in reading how we attempt to get/generate the peripheral's name take a look at this file and the tryGetName method.