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

Something is wrong

Started by PedroBarbosa, 21 December 2012 - 01:24 PM
PedroBarbosa #1
Posted 21 December 2012 - 02:24 PM
Something is wrong can you fix it please?


function Menu()
print("**********WantedLab**********")
print("*						   *")
print("*						   *")
print("*	 ObsidianGenerator	 *")
print("*			V2			 *")
print("*						   *")
print("*						   *")
print("**********WantedLab**********")
print("")
print("How many stacks do you have of redstone?")
stacks = read()
x = stacks

if "x" >= "16" then
print("You cant have more than 15 stacks of redstone")
Cleanall()
Menu()
end

print("Please confirm if you got obsidian in slot n16.")

print("Ready to start?")
write("=> ")
ready = io.read():lower()
if ready == "yes" then
print("Starting")
searchforcleanspaces()
elseif ready == "no" then
print("Your awnser is no")
else
print("Wrong choice")
end
end -- End da funcao

function Cleanall()
term.clear()
term.setCursorPos(1,1)
end -- End da funcao

function searchforcleanspaces()

print("Searching for empty slots")

y = 1

z = 0

for z=1,16 do

turtle.select(y)
if turtle.getItemCount(y) == 0 then
z=z+1
y=y+1
else
y=y+1
end
end

print("Quantity of empty slots")
print(z)
y=1
turtle.select(y)
end -- End da funcao

-- Menu
Cleanall()
Menu()


-- Meaning
-- x = stacks
-- y = slot
-- z = number of empty slots
theoriginalbit #2
Posted 21 December 2012 - 02:34 PM
Please be more specific. what is going wrong? Is it an error? Or is it not functioning properly? or?
ChunLing #3
Posted 21 December 2012 - 02:35 PM
What is wrong? Do you have an error or is the program simply not doing what you want? If the former, post the exact error message.

If the latter, then describe in detail exactly what you want the program to do and what it is doing instead (details).
PedroBarbosa #4
Posted 21 December 2012 - 02:43 PM
Sorry because im Portuguese and i dont know how to write what i am thinking and i try to just be simple…






stacks = read()
x = stacks

if "x" >= "16" then
print("You cant have more than 15 stacks of redstone")
Cleanall()
Menu()
end

On this part this cleans all what i am writing and just dont continue
ChunLing #5
Posted 21 December 2012 - 03:06 PM
You mean that, when you call Cleanall(), it clears the screen before you have time to read the message, "You cant have more than 15 stacks of redstone", and then you restart the menu?

Okay, first, don't use recursion for this. Don't have Menu call Menu, that's just not the way to do this. Second, you probably want to define your more basic functions before any functions that use them, so define Cleanall() before Menu(). Third, some other stuff that's really less important for now.
PedroBarbosa #6
Posted 21 December 2012 - 03:15 PM
Some things arent like that because I translated from Portuguese into English for you guys understand
ChunLing #7
Posted 21 December 2012 - 03:52 PM
Yeah, but you're clearly calling Menu() from inside of Menu() and you really shouldn't do that. Just loop that part of the function until you get the right input. Like:
x = tonumber(stacks)
while x >= 15 do
    Cleanall()
    print("You cant have more than 15 stacks of redstone/nAdjust inventory and Reenter")
    x = tonumber(read())
end
I would have written that whole part differently, but that's just UI (I hope).