trashBlock = {}
newTrashBlock = {}
load(trashBlockFile,trashBlock)
newTrashBlock = trashBlock
resetScreen()
for i=1,#trashBlock do
stringQuestionAsked = "Remove "..trashBlock.."?"
choices = {"Yes I will","No I won't"}
highlighted = 2
Menu()
if choices[1] == chosenOne then
table.remove(newTrashBlock,i)
end
end
trashBlock = newTrashBlock
local file = fs.open("Data/"..trashBlockFile,"w")
for n=1,#trashBlock,1 do
file.writeLine(trashBlock[n])
end
file.close()
The load function works fine but here it is anyway:
function load(fileName,arrayName) –Loading data that is inside File
file = fs.open("Data/"..fileName,"r") – Open a file for reading.
line = file.readLine() – This function reads the next line in the file, until the end.
repeat – Start a loop which will read lines into a table until no lines are left.
table.insert(arrayName,line) – Puts the value of the current line into the table we have.
line = file.readLine() – read the next line
until line == nil – readLine() returns nil when the end of the file is reached.
file.close() – Close up the file ready for use again.
end
The Menu Functions is just a function that centers the text and let's you choose one of the options with your arrow keys. Then it defines the choice you made with return to be the chosenOne.
The resetScreen Function just clears the screen and sets the cursor Position to 1,1.
The Problem I'm having is that if I let's say I have 3 Blocks in my List the first one is minecraft:dirt ,the second one is: minecraft:grass and the third one is minecraft:stone and I want to remove the first one so minecraft:dirt the Program runns through and says:
Remove minecraft:dirt?
I say Yes I do then it removes that from the table now the problem is then the Program says:
Remove minecraft:stone?
which it shouldn't since minecraft:stone is the third one and not the second one anyway I then say No I won't and then
I get the error : attempt to concatenate nil and string. In line: stringQuestionAsked = "Remove "..trashBlock.."?".
I think the problem is that number two has become number one after removing number one and number 3 has become 2 so there is no 3 left.
The only thing I don't get is why that would happen I have two different tables and I am removing from one of them and printing from the other.
I hope you guys can help me because I can't figure this out.