Jump to content


hilburn's Content

There have been 150 items by hilburn (Search limited from 10-February 22)


By content type

See this member's


Sort by                Order  

#193381 Chest/inventory Peripherals

Posted by hilburn on 12 September 2014 - 11:27 AM in Ask a Pro

Point the Proxy at the chest, attach a wired modem to the back, right click it to activate. You will get something like "chest_0 connected" appear in chat. That s the peripheral "side" you should wrap to allow you to call the chest methods



#193372 How would a Pro do it?

Posted by hilburn on 12 September 2014 - 01:14 AM in Ask a Pro

Linked lists are your friend for something like this.
In case you don't know what these are you add a field to each entry called next, this indicates the next entry in the list. You can have multiple nexts, eg nextName, nextAddress, as well as prevName etc if you want. Then when it comes to printing it out, you can do so in order without having done any actual sorting.
An example implementation:
local llist={}
llist[1]={nextName=2,nextSurname=2}


local function addToList(entry)
    llist[#llist+1]=entry
    local thisName=1
    local thisSurname=1
    local nextNameEntry=llist[1].nextName
    local nextSurnameEntry=llist[1].nextSurname
    while llist[#llist].nextName==nil and llist[#llist].nextSurname==nil do
          if nextNameEntry>0 and (llist[nextNameEntry]=nil or llist[nextNameEntry].name>entry.name) then 
                 llist[#llist].nextName=llist[thisName].nextName
                 llist[thisName].nextName=#llist
                 nextNameEntry=-1
          elseif nextNameEntry>0 then
                 nextNameEntry=llist[thisName].nextName
          end
          if nextSurnameEntry>0 and (llist[nextSurnameEntry]=nil or llist[nextSurnameEntry].surname>entry.surname) then 
                 llist[#llist].nextSurname=llist[thisSurname].nextSurname
                 llist[thisSurname].nextSurname=#llist
                 nextSurnameEntry=-1
          elseif nextSurnameEntry>0 then
                 nextSurnameEntry=llist[thisSurname].nextSurname
          end          
     end
end

local function listByName()
    nextName=llist[1].nextName
    while nextName~=nil do
         print(llist[nextName].name.."  "..llist[nextName].surname)
         nextName=llist[nextName].nextName
     end
end

local function listBySurname()
    nextSurname=llist[1].nextSurname
    while nextSurname~=nil do
         print(llist[nextSurname].surname..",  "..llist[nextSurname].name)
         nextSurname=llist[nextSurname].nextSurname
     end
end

I'm pretty sure I've cocked up the implementation of addToList, but it shows you the general shape of how it works. Removing entries basically involves looping through the list and counting your position until your position gets to the entry you want to delete, then just link the previous entry to the next entry and it will vanish from the list (don't forget to set that entry to nil, but don't use table.remove as that will break everything)

They are a very powerful tool and well worth looking into



#193332 Chest/inventory Peripherals

Posted by hilburn on 11 September 2014 - 10:42 AM in Ask a Pro

If you have OpenPeripherals then yes, this is doable. However for "remote" chests (ones not adjacent so you are using modems) you will need to use the OpenP Peripheral Proxy block to connect to it. There are also methods to support AE systems, as well as automatically craft and pull items from it



#193298 [Math] Matrices

Posted by hilburn on 10 September 2014 - 04:21 PM in Ask a Pro

Matrices don't really have a direct equivalence to Division other than What Lyqyd suggested. However you have to remember the non-commutability of matrices. This means that unlike numbers where a*b=b*a, [A]*[B]!=[B]*[A]

So: on to division. The simple way to think about it is that any matrix can be represented as the product of 2 other matrices (even if one of those matrices is the index)

So [C]=[A]*[B] where [B] is defined as the matrix we want to "divide" by. We achieve this by post-multiplying (remember order is important) by the inverse of [B], [B]^(-1) to get

[C]*[B]^(-1) = [A]*[B]*[B]^(-1) = [A]

Where [A] is the matrix that when multiplied by [B], gives [C]. Which is pretty close, but not exactly, what the result of a division is.



#193143 Big Reactor and Energy Cell Control

Posted by hilburn on 08 September 2014 - 11:20 AM in Ask a Pro

An alternative solution, which actually gives you better fuel efficiency is to connect a pair of rednet ports with cable, output energy stored from one, and send it to fuel rod % on the other. Your reactors output will stabilize with your fuel consumption



#193129 Redstone signal not emmiting

Posted by hilburn on 08 September 2014 - 07:56 AM in Ask a Pro

it's not so much that it is only turning it on if turbine 2 is offline, it's that if reactor 2 is online, it turns the signal back off again when the code gets to there. There a couple of options to how you could fix this. but my suggestion would be to have 2 booleans, turbine1active and turbine2active which are set to true or false instead of the redstone output. then at the very end of the loop do something like:

if turbine1active or turbine2active then
	rs.setOutput("top",false)
else
	rs.setOutput("top", true)
end

Additionally, you could make your code much more compact if you used tables to store your peripherals, so instead of mon1, mon2 you have mon[1] and mon[2], that way you could just loop through your sensing/display code twice, with "for i=1,2 do"

hope this helps



#192954 Dynamic Analog Output?

Posted by hilburn on 03 September 2014 - 09:04 PM in Ask a Pro

you could do either, but I definitely recommend the latter, a grid of buttons labelled 1-15 with a number (tbh you could even use the label of the button) associated with each that is passed to the on-click event



#192925 Dynamic Analog Output?

Posted by hilburn on 03 September 2014 - 04:00 PM in Ask a Pro

there is absolutely nothing wrong with having something like:

local function buttonTouch(button_num)
   rs.setAnalogOutput("back",button_num)
end



#192801 rednet.send variable + string

Posted by hilburn on 01 September 2014 - 09:44 PM in Ask a Pro

A relatively easy way to do this would be to just send the text in the first message and then the contents of the variable in the second.

Alternatively if you really want to send it in one you could do something with string functions. Something like:

local anzahl=io.read()
rednet.send(13,"<anzahl>"..anzahl.."</anzahl>".."hello")

and then on the receiving computer:

temp=string.sub(msg,string.find(msg,"<anzahl>(.-)</anzahl>")) --#removes the "hello" and anything else not included within the <></> tags
temp=string.gsub(temp,"<(.-)>","") --#removes the tags
local anzahl=temp --#returns the variable



#192704 Let turtle place a turtle with a startup program

Posted by hilburn on 31 August 2014 - 05:41 PM in Ask a Pro

Generally the best solution is to have an installer program called "startup" on a disk drive along with all the programs that you want the turtle to use, you can then reboot the computer and the startup program will copy all the files across to the turtle



#192570 TC Smeltery problem.

Posted by hilburn on 30 August 2014 - 12:11 AM in Ask a Pro

Unfortunately since I wrote that code I've had to scrub my laptop so lost a lot of scripts that I foolishly didn't backup. That said it was fairly simple so here is a quick guess at what it looked like:

tank=peripheral.wrap("back")
while true do
   output=false
   for _,liquid in pairs(tank.getLiquid()) do --#check this is the function, there is one which will return an array of liquid data for the smeltery
        if liquid.name=="liquid.emerald" then --#not sure if this is the field or that's the name of liquid emerald, again you'd need to test that
             output=true
        end
   end
   rs.setOutput("right",output)
   sleep(2)
end



#192484 TC Smeltery problem.

Posted by hilburn on 28 August 2014 - 05:01 PM in Ask a Pro

You have to to wrap a smeltery drain to access the contents of the tank.

I actually made a program you might like to use, it's designed to trade for pages but you can just cut that bit out if you want emeralds. the setup is reasonably well explained though

http://www.computerc...penperipherals/



#192241 Sorting Lua Tables: Multiple Columns

Posted by hilburn on 26 August 2014 - 08:45 AM in Ask a Pro

Just a a thought:
For generating the points why not just solve the circle equation? you onto need to do it in the +ve x and +ve y quadrant and then rotate it to the other quadrants. In my head it looks something like:
local function rotate(point, quadrants)
   if quadrant==1 then
	  return -point.z, point.x, point.theta+math.pi/2
   elseif quadrant==2 then
	  return -point.x, -point.z, point.theta+math.pi
   end
end

for x=0,r,0.1 do --#necessary to do steps smaller than 1 for cases when there are more than 1 block per x value
	z=math.floor((r^2-x^2)^0.5)
	xfloor=math.floor(x)
	points[#points+1]={["x"]=xfloor,["z"]=z,["theta"]=math.atan2(x,z)}
end
for i,j in pairs(points) do
	if j.x==points[i+1].x and j.z==points[i+1].z then
		table.remove(points,i+1) --#strips duplicate points from the table
	end
end
table.sort(points, function(p1,p2) return p1.theta<p2.theta end) --#sort table (though it should already be sorted by our generation method)

for= thetaoffset=1,2 do
    for i,j in pairs(points) do
       points[#points+1]={rotate(j,offset)}
    end
end

not saying this would work perfectly without some tweaking, but it could be a good starting point



#192202 Sorting Lua Tables: Multiple Columns

Posted by hilburn on 25 August 2014 - 11:12 PM in Ask a Pro

Why not store the table in the format:

{[1]={x=1,y=0,theta=0},[2]={x=1,y=1,theta=45},...}

you could then use

table.sort(table, function(point1,point2) return point1.theta<point2.theta end)

to sort it, alternatively, if you didn't want to store the angle in the table, you could modify the comparison function to calculate the angles and then compare them



#192200 Minor problems with a timer loop

Posted by hilburn on 25 August 2014 - 11:00 PM in Ask a Pro

I normally try to minimise the amount of checks I use and try to use in order of preference ==, ~=, <, >, <=, >=, I do't know if it has any effect in Lua, but I remember being taught that on microcontrollers that's the order of speed, so I would rewrite your final if statement as something like this:

if events[1] == "mouse_click" and events[2] == 1 then
   if events[4]==8 and events[3]~=1 then
	  if events[3] < 5 then
		 ...
	  elseif events[3] < 7 then
		 ...
	  end
   end
   ...
end

the same logic could be used earlier in your program with your other ifs however another thing I would tend to do in this case would be to create a lookup table with keys from 0 to 100 that listed the colour to use, so instead of doing a big control statement where really the only thing you are changing is the colour you are using as the background, you just pass

term.setBackgroundColour(colourLookup[fluidInfo[selected].percent])

As again, a lookup is faster than a bunch of ifs

I'm not sure how much this will help, but I hope it does a bit



#191389 little lost on program

Posted by hilburn on 17 August 2014 - 01:17 AM in Ask a Pro

Basically it's just saying that the aspectalyzer doesn't have that method, try calling listMethods() or getMethods() to see what is available, it might be something silly like it's getAspect() rather than getAspects()



#191023 variables and API's. How do I properly reference to them?

Posted by hilburn on 13 August 2014 - 08:33 PM in Ask a Pro

why not do:
location=textutils.serialize(locationfile.readall())


much better to use vectors/tables for doing location stuff



#190996 How Do I Make a Toggle menu

Posted by hilburn on 13 August 2014 - 06:28 PM in Ask a Pro

Hmmm well right off the bat, bundled cable doesn't really work at the moment, if you have Project Red (or equivalent) and Wireless Redstone I would suggest wrapping a transmitter and receiver as peripherals and using those. The system Would work something like this:

Previously set up: Receiver on Frequency (X) goes into a T flip flop, output of this goes to the lights and a transmitter on frequency (X+1)
Computer can find the status of the lights by setting it's receiver to frequency (X+1), can toggle the status of the lights by transmitting on X eg.

function TurnOn(freq)
    receiver.setFreq(freq+1) --#set receiver to the monitoring frequency
    if not rs.getInput("left") then --#if it's not on
         transmitter.setFreq(freq)  --#set transmitter to the toggle frequency
         rs.setOutput("back",true)
         sleep(0.1)
         rs.setOuptut("back",false) --#pulse the frequency to toggle the lights on
    end
end


As for the menu itself you could do use tables which would make it quite neat. Something like:
menu={[1]={menudisplay="Fence Lighting", selecttext="Fence Lighting Control Selected", submenu=
			{[1]={menudisplay="Turn Off", selecttext="Turning Fence Lighting Off", selectfunction=turnOff(1)},
			 [2]={menudisplay="Turn On", selecttext="Turning Fence Lighting On", selectfunction=turnOn(1),
             [3]=...}

You could then have a function called DisplayMenu which would do something like:

function DisplayMenu(dmenu)
    for i,j in pairs(dmenu) do
        print("["..i.."] "..j.menudisplay) --#prints out all the menu items of the table supplied to it
    end
    input=0
    while not (input>0 and input<=#menu) do   --#loops until valid input
        input=read()
    end
    print(dmenu[input].selecttext)            --#print out the confirmation text
    if dmenu[input].submenu then           --#if there is a submenu
        DisplayMenu(dmenu[input].submenu)  --#display it
    else                                                           --#otherwise
        dmenu[input].selectfunction                  --#do the function the menu item is tied to
    end
end



#190881 AppliedEnergetics and CC Project

Posted by hilburn on 12 August 2014 - 07:57 PM in Ask a Pro

At the beginning of each of your if statements you have made a typo

shell.run("clear") not shell.run"clear"

even better is
term.clear()



#190820 Tinkers Construct & Computercraft?

Posted by hilburn on 12 August 2014 - 07:47 AM in Ask a Pro

Not in the version of TiC I've tested with, but tbh even if it did work, it'd easier (and cheaper) to use the crafting station



#190791 Tinkers Construct & Computercraft?

Posted by hilburn on 12 August 2014 - 02:05 AM in Ask a Pro

If you place a crafting station next to the tool station you can do it by placing items into the crafting grid, but the tool station doesn't let you automate the inventory



#190615 Help! i Cant Craft A Advance Computer!

Posted by hilburn on 10 August 2014 - 10:47 PM in Ask a Pro

Are you on a custom modpack? check for any ID conflicts that may have resulted in the advanced computer being overwritten



#190347 False AND True goes to then all the time

Posted by hilburn on 07 August 2014 - 02:18 AM in Ask a Pro

Just an FYI, when testing for booleans "if bool==true then..." is unnecessary, you can just do "if bool then..."

Are you sure you haven't typo'd? Or declared one of the variables as a local in a different function so your if can't see it and so reads it as nil?

Other than those generalities I can't help without code :)



#190330 magnet turtle help!

Posted by hilburn on 06 August 2014 - 11:16 PM in Ask a Pro

Magnet turtle is OpenBlocks IIRC and yes you have to wrap it.



#190092 Crashing when placing BC Quarry

Posted by hilburn on 04 August 2014 - 07:03 PM in Ask a Pro

Strange question, you you can place it yourself right?

What about other ways of automated placing, autonomous activator/block placer etc.. because that seems to be a BC issue not a CC one (though I am not the best at deciphering crashlogs)