- ComputerCraft | Programmable Computers for Minecraft
- → Zamithal's Content
Zamithal's Content
There have been 28 items by Zamithal (Search limited from 10-February 22)
#139423 [Open Peripherals] function only works once
Posted by
Zamithal
on 11 August 2013 - 09:29 AM
in
Ask a Pro
#139399 [Open Peripherals] function only works once
Posted by
Zamithal
on 11 August 2013 - 07:26 AM
in
Ask a Pro
function changeBoxHeight(desiredHeightChange, object, speed, direction)
local boxWidth = object.getWidth();
local boxHeight = object.getHeight();
local boxX = object.getX();
local boxY = object.getY();
print(object.getHeight());
for i = 1, desiredHeightChange/5 do
object.delete();
if direction == "up" then
object = net.addBox(boxX, boxY, boxWidth, boxHeight - 5*i, 0xFFFFFF, 0.5);
end
if direction == "down" then
object = net.addBox(boxX, boxY, boxWidth, boxHeight + 5*i, 0xFFFFFF, 0.5);
end
sleep(speed);
end
end
This function works perfectly..once, after it fires once whatever I put in for object will return nil if
variable.getHeight();is asked of it. Any idea what I did wrong?
#65816 Error: concatenate nil and string.
Posted by
Zamithal
on 29 December 2012 - 01:47 PM
in
Ask a Pro
rednet.open("back")
invalid = "ERROR: Not a valid floor."
f = {}
f[1] = "Automation"
f[2] = "Storage"
f[3] = "Agriculture"
f[4] = "Reactor control"
f[5] = "Matter generation"
f[6] = "Matter generation 2"
f[7] = "Living space"
f[8] = "Library"
f[9] = "Danger room"
f[10] = "Roof"
f[11] = invalid
f[12] = invalid
f[13] = invalid
f[14] = invalid
f[15] = invalid
f[16] = invalid
g = {}
g[1] = "white"
g[2] = "Lightblue"
g[3] = "yellow"
g[4] = "magenta"
g[5] = "purple"
g[6] = "lime"
g[7] = "orange"
g[8] = "red"
g[9] = "pink"
g[10] = "green"
g[11] = "brown"
g[12] = "cyan"
g[13] = "blue"
g[14] = "black"
g[15] = "gray"
g[16] = "lightGray"
while true do
e, p1, p2 = os.pullEvent()
if e == "rednet_message" then
rednet.send(p1, "Floor " .. p2 .. ", " .. f[p2] .. " accepted.")
if colors[g[p2]] then rs.setBundledOutput("right", colors[g[p2]]) end
elseif e == "redstone" then
rs.setBundledOutput("right", rs.getBundledInput("left") == 0 and rs.getBundledOutput("right") or rs.getBundledInput("left"))
end
end
the error is line 44 " rednet.send(p1, "Floor " .. p2 .. ", " .. f[p2] .. " accepted.")" concatenate nil and string
#65013 Running parallel?
Posted by
Zamithal
on 27 December 2012 - 07:22 PM
in
Ask a Pro
redstone.setBundledOutput("right", "colors."color)
but that didn't work so i moved to elseifs....So, replacing the elseif functions i'm still left with parallel:4:Coroutine limit of 50 reached, and Lyqyds code works, but i would like the latest input to stay on, and i don't understand enough of it to change it myself.
What I THINK i have gathered:
e is the event?
p1 is the sender ID?
p2 is the message recieved?
colors[variable] is the proper form of "colors."color correct?
edit: ok coroutine fixed
edit 2: I lied, it isn't fixed by putting the while true's inside the function
#65004 Running parallel?
Posted by
Zamithal
on 27 December 2012 - 06:49 PM
in
Ask a Pro
rednet.open("top")
function getColor()
if redstone.testBundledInput("left", colors.white) == true then
color = "white"
elseif redstone.testBundledInput("left", colors.lightBlue) == true then
color = "lightBlue"
elseif redstone.testBundledInput("left", colors.yellow) == true then
color = "yellow"
elseif redstone.testBundledInput("left", colors.magenta) == true then
color = "magenta"
elseif redstone.testBundledInput("left", colors.purple) == true then
color = "purple"
elseif redstone.testBundledInput("left", colors.lime) == true then
color = "lime"
elseif redstone.testBundledInput("left", colors.orange) == true then
color = "orange"
elseif redstone.testBundledInput("left", colors.red) == true then
color = "red"
elseif redstone.testBundledInput("left", colors.pink) == true then
color = "pink"
end
end
function getReading()
local senderId, message, distance = rednet.receive()
color = message
end
function getTrueColor()
if color == "white" then
trueColor = 1
elseif color == "lightBlue" then
trueColor = 8
elseif color == "yellow" then
trueColor = 16
elseif color == "magenta" then
trueColor = 4
elseif color == "purple" then
trueColor = 1024
elseif color == "lime" then
trueColor = 32
elseif color == "orange" then
trueColor = 2
elseif color == "red" then
trueColor = 16384
elseif color == "pink" then
trueColor = 64
end
redstone.setBundledOutput("right", trueColor)
end
while true do
parallel.waitForAny(getColor(), getReading(), getTrueColor)
end
Can someone explain to me what is wrong with this code? it never turns on any output (I have not tried brodcasting it a message yet, just the wire inputs.)
#64914 Does ccSensors actually work on tekkit?
Posted by
Zamithal
on 27 December 2012 - 02:11 PM
in
Ask a Pro
os.unloadAPI("/rom/apis/sensorsAPI")
os.unloadAPI("/rom/apis/sensorsData")
os.unloadAPI("/rom/apis/sensorsUI")
os.loadAPI("/rom/apis/sensorsAPI")
os.loadAPI("/rom/apis/sensorsData")
os.loadAPI("/rom/apis/sensorsUI")
function printDict(data)
for i,v in pairs(data) do
print(tostring(i).." - "..tostring(v))
end
end
ctrl = sensors.getController()
data = sensors.getSensors(ctrl)
printDict(data)
This code should return a list of all connected sensors from the adjacent Sensor Controller...problem is, it just returns 1 sensor named "Sensor" ( I have 6 named sensors)I tested this in single player, works fine, not on SMP though, so is ccSensors-B017pr2 broken?
#64451 Simple bundled command?
Posted by
Zamithal
on 26 December 2012 - 12:37 PM
in
Ask a Pro
if redstone.getBundledInput ("bottom", colors.red) == true then
print("YES!")
else
print("NO!")
end
This always returns no and I cannot figure out why, the red wire is on and I have a jacketed bundled cable running up to the bottom of my turtle...any ideas?
No error is returned, only "NO!"
#64204 Whats wrong with my function?
Posted by
Zamithal
on 25 December 2012 - 05:14 PM
in
Ask a Pro
function farmLine() -- farm 1 collum
repeat
loc:forward
until turtle.detect() == true
repeat
turtle.select(14)
if turtle.compareDown() == true then
loc:right()
loc:right()
loc:forward()
loc:left()
loc:left()
turtle.dig()
turtle.select(1)
turtle.place()
else
loc:right()
loc:right()
loc:forward()
loc:left()
loc:left()
until loc.x == 0
repeat
loc:left()
until loc.h == 2
end
the loc: comands are from Lyqud's location API and there isn't a problem with those.
Error is: line 7 function arguments expected.
#64190 Whats wrong with my function?
Posted by
Zamithal
on 25 December 2012 - 03:54 PM
in
Ask a Pro
function fillSlot(slot) -- finish the stack until turtle.getItemSpace(slot) == 0 -- repeat until stack is complete turtle.select(slot) -- select slot turtle.suck() -- try to fill slot if turtle.getItemSpace(slot) == 0 then -- if slot was filled turtle.suckDown() -- pick up all non matching items for i = 1, 16 do --empty all items except for kept slots if i == 1 or i == 4 or i == 13 or i == 15 or i == 16 then -- kept slots -- Do nothing else turtle.select(i) -- select non-kept slot turtle.drop() --place in chest end end else -- if slot was not filled for i = 1, 16 do --empty all items into "temporary holding area" except for kept slots if i == 1 or i == 4 or i == 13 or i == 15 or i == 16 then -- kept slots -- Do nothing else turtle.select(i) -- select non-kept slots turtle.dropDown() -- drop on floor (under turtle) end end end end end fillSlot(1)
The error is Line 2 'end' expected to close function, but i believe I have all the ends
#64164 turtle.transferTo work around
Posted by
Zamithal
on 25 December 2012 - 12:29 PM
in
Ask a Pro
#63896 Keeping track of turtle location
Posted by
Zamithal
on 24 December 2012 - 07:06 PM
in
Ask a Pro
Oh, nevermind, I just noticed that you mentioned loc:forward() changes the value of loc
#63886 Keeping track of turtle location
Posted by
Zamithal
on 24 December 2012 - 06:25 PM
in
Ask a Pro
Lyqyd, on 24 December 2012 - 04:41 PM, said:
local loc = location.new()
handle = io.open("/.loc", "w")
if handle then
handle:write(tostring(loc))
handle:close()
end
local loc
handle = io.open("/.loc", "r")
if handle then
local x, y, z, h = string.match(handle:read(), "(%-?%d+),(%d+),(%-?%d+),(%d)")
loc = location.new(tonumber(x), tonumber(y), tonumber(z), tonumber(h))
handle:close()
end
function readLocation(loc)
local loc = location.new()
handle = io.open("/.loc", "r")
if handle then
local x, y, z, h = string.match(handle:read(), "(%-?%d+),(%d+),(%-?%d+),(%d)")
loc = location.new(tonumber(x), tonumber(y), tonumber(z), tonumber(h))
handle:close()
end
end
-----------------------------------------------------
function saveLocation(loc)
handle = io.open("/.loc", "w")
if handle then
handle:write(tostring(loc))
handle:close()
end
end
readLocation()
loc:back()
saveLocation()
print(loc)
This is my code, it prints properly, however if I look at the .loc file... it tells me the value is nil. However, this code works, but id much rather it be a function local loc = location.new()
handle = io.open("/.loc", "r")
if handle then
local x, y, z, h = string.match(handle:read(), "(%-?%d+),(%d+),(%-?%d+),(%d)")
loc = location.new(tonumber(x), tonumber(y), tonumber(z), tonumber(h))
handle:close()
end
print (loc)
loc:forward()
handle = io.open("/.loc", "w")
if handle then
handle:write(tostring(loc))
handle:close()
end
print (loc)
#63867 Keeping track of turtle location
Posted by
Zamithal
on 24 December 2012 - 04:04 PM
in
Ask a Pro
direction = 1 turtleOneXCoord = 0 turtleOneZCoord = 0 while true do direction = 1 turtleOneXCoord = 0 turtleOneXCoord = 0 while true do -- some sort of input to go forward 1 square if direction == 1 then turtle.forward() turtleOneXCoord = turtleOneXCoord + 1 elseif direction == 2 then turtle.forward() turtleOneZCoord = turtleOneZCoord + 1 elseif direction == 3 then turtle.forward() turtleOneXCoord = turtleOneXCoord - 1 elseif direction == 4 then turtle.forward() turtleOneZCoord = turtleOneZCoord - 1 end --some sort of input to turn right direction = direction + 1 --some sort of input to turn left direction = direction - 1 endwith this, I can note down coordinates important to the turtle (like a restock chest)
However, the problem with this is if the program is terminated, and the turtle is not at (0,0), (0,0) is then moved and all reference coordinates would be thrown off... so a few questions...
1. Is this the best way to keep track of the turtle?
2. Can i save information without storing it to a file with the vault API?
3. If no, can someone explain how to use the vault API a little bit more thoroughly to me?
#62275 CCSensors D:
Posted by
Zamithal
on 20 December 2012 - 09:54 PM
in
Ask a Pro
function printDict(data) for i,v in pairs(data) do print(tostring(i).." - "..tostring(v)) end end ctrl = sensors.getController() -- set the Sensor Controler's data data = sensors.getSensors(ctrl) SENSOR = data[1] data = sensors.getProbes(ctrl,SENSOR) SENSProbe = data[2] data = sensors.getAvailableTargetsforProbe(ctrl,SENSOR,SENSProbe) SENSPos = data[1] data = sensors.getSensorReadingAsDict(ctrl,SENSOR,SENSPos,SENSProbe) print(data.TotalItems)Thats my code that I just tested, prints 0 items for an empty chest.
#61826 CCSensors D:
Posted by
Zamithal
on 19 December 2012 - 06:13 PM
in
Ask a Pro
----------------------getEMCInformation----------------------------------- ctrl = sensors.getController() -- set the Sensor Controler's data data = sensors.getSensors(ctrl) -- Find and access the Sensor Controler, bring up all avaiable sensors. EMC = data[3] -- The EE Sensor Module is thrid on the list, pick it, make note of it. data = sensors.getProbes(ctrl,EMC) -- Bring up a list of avalable options (TargetInfo, Collector, Furnace ect.) EMCProbe = data[2] -- Pick #5 Because we are using a condesor data = sensors.getAvailableTargetsforProbe(ctrl,EMC,EMCProbe) -- Get available blocks EMCPos = data[1] -- Select the first condensor seen data = sensors.getSensorReadingAsDict(ctrl,EMC,EMCPos,EMCProbe) -- GET THE DATA!! ---------------------printEMC-------------------------- print(data.displayEnergy) -- Print the current reading to the screenIm fairly new at this so this is probably not the correct way to do it, but it works...
As for the checking items thing, do the same process and use a Inventory Sensor Module instead..
PS. Put this at the top of your code
function printDict(data) for i,v in pairs(data) do print(tostring(i).." - "..tostring(v)) end endand then use printDict(data) whenever your not sure what data[x] your supposed to pick, its helped me lots!
#61812 [Question] Damage Values?
Posted by
Zamithal
on 19 December 2012 - 05:52 PM
in
Ask a Pro
anonimo182, on 19 December 2012 - 04:32 PM, said:
Example:
for i = 1, #nameOfTheTable do print(nameOfTheTable[i]) end
- ComputerCraft | Programmable Computers for Minecraft
- → Zamithal's Content


