9 posts
Posted 28 March 2013 - 04:00 PM
Code
if turtle.getFuelLevel() < 1000 then
turtle.select(16)
turtle.refuel(64)
end
function refillMaterials()
slot = 1
repeat
if turtle.getItemCount(slot) < 1 then
slot = slot + 1
turtle.select(slot)
end
until
slot == 17
slot = slot - 16
noMaterials()
end
function noMaterials()
term.clear
term.setCursorPos(1,1)
print("Out of materials please bring me more")
print("press any key to continue...")
event1, param1 = os.pullEvent()
refillMaterials()
end
function placeBlock( times )
for i = 1, times do
turtle.placeDown()
turtle.forward()
end
end
function Corner()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
placeBlock(2)
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
placeBlock(1)
turtle.turnRight()
turtle.forward()
placeBlock(2)
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
function buildLayer()
placeBlock(5)
Corner()
placeBlock(5)
Corner()
placeBlock(5)
Corner()
placeBlock(5)
Corner()
end
function BuildCylinder( height )
for i = 1, height do
buildLayer()
refillMaterials()
turtle.up()
end
end
print("How tall should the cylinder be?")
local height = tonumber(read())
turtle.select(1)
BuildCylinder(height)
Ok so it's saying = expected for line 21 but it's gibberish I don't need a equals there what's the matter with this I think I have just been staring at it to long can anyone tell me whats wrong?
1688 posts
Location
'MURICA
Posted 28 March 2013 - 04:03 PM
On the line after "function noMaterials()", there should be () after term.clear.
7508 posts
Location
Australia
Posted 28 March 2013 - 06:11 PM
On the line after "function noMaterials()", there should be () after term.clear.
so yes really, it was expecting an = sign :P/>
1688 posts
Location
'MURICA
Posted 28 March 2013 - 06:51 PM
Mhm. Lua looks for variable definitions before function calls.
9 posts
Posted 29 March 2013 - 02:42 AM
Makes much more sense now I had been working on it all day and was getting a bit loopy :S anywho thanks alot it's coming along quite nicely I'm trying to make a whole bunch of basic functions for building shapes then im gonna assign them to multiple turtles and build a fortress of sorts on my Feed the Beast server lol :D/>
9 posts
Posted 29 March 2013 - 05:55 AM
hmm now I have go to another one that's stumping me
CodeSpoiler
slot = 1
if turtle.getFuelLevel() < 1000 then
turtle.select(16)
turtle.refuel(64)
end
function antiObstruct()
if turtle.detectDown() then
turtle.digDown()
end
if turtle.detectUp() then
turtle.digUp()
end
if turtle.detect then
turtle.dig()
end
end
function refillMaterials()
while turtle.getItemCount(slot) < 1 do
slot = slot + 1
turtle.select(slot)
if slot == 16 then
slot = slot - 15
turtle.select(slot)
end
end
end
function noMaterials()
term.clear()
term.setCursorPos(1,1)
print("Out of materials please bring me more :(/>/>/>/>")
print("press any key to continue...")
event1, param1 = os.pullEvent()
refillMaterials()
end
function placeBlock(times)
for blocks = 1, times do
turtle.placeDown()
turtle.forward()
end
end
-- Build cylinder code
function corner()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
placeBlock()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turle.turnLeft()
placeBlock()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
placeBlock()
turtle.turnRight()
turtle.forward()
end
function buildCylinderLayer()
placeBlock(6)
corner()
placeBlock(6)
corner()
placeBlock(6)
corner()
placeBlock(6)
corner()
end
function buildCylinder( cylinderHeight )
for cylheight = 1, cylinderHeight do
buildCylinderLayer()
turtle.up()
end
end
-- Build cylinder code
-- Build wall code
function wallLayer()
placeBlock(19)
turtle.placeDown()
wallCorner()
placeBlock(19)
turtle.forward()
turtle.placeDown()
wallCorner()
turtle.up()
end
function wallCorner()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
end
function wallDirection( direction )
for wallDir = 1, direction do
if direction == 1 then
turtle.turnLeft()
turtle.forward()
else
if direction == 2 then
turtle.forward(9)
turtle.turnRight()
turtle.forward(4)
turtle.turnLeft()
turtle.forward()
else
if direction == 3 then
turtle.forward(5)
turtle.turnRight()
turtle.forward(14)
else
if direction == 4 then
turtle.turnRight(2)
turtle.forward(4)
turtle.turnLeft()
turtle.forward(9)
turtle.turnRight()
turtle.forward()
else
end
end
end
end
end
end
function buildWall( wallHeight )
for wallH = 1, wallHeight do
wallLayer()
end
end
-- Build wall code
term.clear()
term.setCursorPos(1,1)
print("How tall should the Castle be?")
local height = tonumber(read())
turtle.select(1)
-- Start building!
buildCylinder(height)
wallDirection( math.random (1,4) )
buildWall()
-- Done Building
and it's telling me
818 posts
Posted 29 March 2013 - 05:58 AM
"times" is not a defined variable
233 posts
Location
Cleveland, Ohio
Posted 29 March 2013 - 06:04 AM
you must define "times"
if you dont define it, just do the number
9 posts
Posted 29 March 2013 - 06:14 AM
oh I feel like an idiot now it Notepad++ was saving it as a .txt instead of blank and the turtle didn't have the new code lol now it's working like a charm now all I need is to fix my function refillMaterials() and I can start on my randomly generated castle :D/>
9 posts
Posted 29 March 2013 - 08:21 AM
Hmm why doesnt this work
function refillMaterials()
Curslot = 1
if turtle.getItemCount(Curslot) < 1 then
if Curslot == 16 then
Curslot = Curslot - 15
noMaterials()
else
Curslot = Curslot + 1
turtle.select(Curslot)
end
end
end
it doesnt give me any erros but it ingores but im calling everytime a place a block
function placeBlock(times)
for blocks = 1, times do
refillMaterials()
turtle.placeDown()
turtle.forward()
end
end
any insight?
318 posts
Location
Somewhere on the planet called earth
Posted 29 March 2013 - 08:29 AM
I am not sure if I understand whats wrong 100% but, it will never ever go to a slot higher than 2. Each time you call the function you reset Curslot to 1. So when slot 1 is empty it selects slot two, then when you place again it selects slot 2 again. And thus slot two may be empty and it will not place anything.
9 posts
Posted 29 March 2013 - 08:57 AM
hmm that helps so maybe Curslot should be a global varible so it stays constant?
Edit: Yep that fixed it but the entire turtle has to be full otherwise it wont place a block when called the swap to next slot i figure something better out later
131 posts
Location
I am omnipresent... DUH
Posted 02 April 2013 - 12:10 PM
Edit: Failure to read properly