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

[LUA] My program wont do what is supposed to do

Started by Qunatomy, 27 March 2013 - 04:47 AM
Qunatomy #1
Posted 27 March 2013 - 05:47 AM
Hello,
i'm just frustrated from my program.. it wont work as i want it to be
the program is programmed to flat an area given to it(example: you write from a wireless computer "flat 5 5" so it should flat 5 by 5 area and the Y (height) of it should be untill it wont detect any block under it.

here is the program:(ill explain it)

 

– Receiving the message & variables
local senderId , message, distance = rednet.receive()
local i = 0
local l = (message) - 1
local tp = 10
local senderId, message, distance = rednet.receive()
local w = (message)
local gm = w + l
local blkswu = 0
–Functions
function turnos()
turtle.turnRight()
turtle.turnRight()
end
function goback()
for i = 0,l do
turtle.forward()
end
end
function dig()
if turtle.detect() == true then
turtle.dig()
end
end
function forward()
if turtle.detect == false then
turtle.forward()
end
end
function mineUp()
if turtle.detectUp == true then
turtle.digUp()
turtle.up()
blkswu = blkswu + 1
repeat until turtle.detectUp == false
end

end
function godown()
for i = 0,blkswu do
turtle.down()
end
end
function filldown()
if turtle.detectDown() == false then
turtle.select(2)
turtle.placeDown()
end
end
function nl()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
function mine()
if gm == l+w then
for i = 0,l do
i = i + 1
filldown()
dig()
forward()
mineUp()
godown()
filldown()
end
end
end
function back()
turnos()
goback()
turnos()
end
function all()
for i = 0,w do
i = i + 1
mine()
back()
nl()
end
end
– getting all together
all()


o.k this is the program
the first part - getting the message and variables
is just receiving the message and setting the variables in the first part
the message is just from a wireless computer that sends 2 variable
that are a length and width of the area i want to flat
after this first part is setting up the functions as u can see function for every move
it also should fill the floor and the ceiling with the dirt(cobble etc) that is starts with in the second place
there is 2 main functions : mine() and all()
mine is just- 1. checks if there is an empty block under it and if it's empty it just fill it
2. if there is a block infront of it it will dig it
3. it will go forward if there is no block infront of it
4. it will mine up untill there is no block above him
5.after there is no block above him he will come down the same blocks he went up
6.he will check again if there is block below him and he will fill that up

im kinda new with this mod and every thing but i think i have a basic understanding of stuff..
i allready made a program that will do the same but it will mine up 3 block
and the length&width will adjustable by the user

and i wanted to make a flat area programs on the same thing

instead of doing as it supposed to do
i told it to flat 5 by 3
from where it started and instead it mined 1 block and went back
here is a picture of where it started and where it was supposed to do 5 by 3 and where it end up in

thanks very much and i hope you guys will find my problem


Qunatomy #2
Posted 27 March 2013 - 11:47 AM
guys please can some one reply this post and help me?
JokerRH #3
Posted 27 March 2013 - 02:05 PM
You forgot the brackets in forward and mineup.
That means instead of calling the detect function you check if the function is a boolean false variable.
Brandhout #4
Posted 27 March 2013 - 02:28 PM
You forgot a load of brackets everywhere. Whenever u use functions like turtle.detectUp() and turtle.forward() don't forget the brackets.

Also there are quite a few if statements that feel quite superfluous. Like checking if there is a block in front before moving. Nothing breaks when u use the turtle.forward() command but when there is a block in front. It will simply return false.

This part also has a few errors:

function mineUp()
  if turtle.detectUp == true then
  turtle.digUp()
  turtle.up()
  blkswu = blkswu + 1
  repeat until turtle.detectUp == false
end
end
U forgot "()" twice. Also you misuse repeat. , this current repeat statement will cause an infinite loop and shut down ur turtle…… It works like:

repeat
  --statement
until not turtle.detectUp()
This will execute the statement until it no longer detects a block above the turtle.

A while loop seems more useful, this first checks the condition before it executes the statement. If the turtle does not detect anything above it, nothing will hapen.

while turtle.detectUp() do
  turtle.digUp()
  turtle.up()
  blkswu = blkswu + 1
end
LordIkol #5
Posted 28 March 2013 - 02:15 AM
Hi together,

Here is some code could not test but maybe it helps you a littl bit will check when im back Home.

http://pastebin.com/5hDms45G

greets
Loki
Edited on 28 March 2013 - 01:17 AM
Qunatomy #6
Posted 29 March 2013 - 01:00 AM
thanks u guys all i fixed the program as i should be
now im working on a mine program that u adjust the length width and height